question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

transparent implicit conversion macro not emitting the proper error

See original GitHub issue

Among various inlining and macro usages, only transparent macro does not emit the error message reported inside.

Compiler version

3.0 master branch

Minimized code

Main code:

import scala.language.implicitConversions
inline def inlineError : Unit =
  compiletime.error("inlineError")
transparent inline def transparentInlineError : Unit =
  compiletime.error("transparentInlineError")

trait InlineConversion
object InlineConversion:
  inline implicit def fromInt(i : Int) : InlineConversion =
    compiletime.error("inlineConversionError")

trait TransparentInlineConversion
object TransparentInlineConversion:
  transparent inline implicit def fromInt(i : Int) : TransparentInlineConversion =
    compiletime.error("transparentInlineConversionError")

import scala.quoted.*

inline def macroError : Unit = ${macroErrorInternal}
def macroErrorInternal(using Quotes) : Expr[Unit] =
  import quotes.reflect.*
  report.error("macroError")
  '{}

transparent inline def transparentMacroError : Unit = ${transparentMacroErrorInternal}
def transparentMacroErrorInternal(using Quotes) : Expr[Unit] =
  import quotes.reflect.*
  report.error("transparentMacroError")
  '{}

trait MacroConversion
object MacroConversion:
  inline implicit def fromInt(i : Int) : MacroConversion = ${fromIntInternal}
  def fromIntInternal(using Quotes) : Expr[MacroConversion] =
    import quotes.reflect.*
    report.error("macroConversionError")
    '{???}
trait TransparentMacroConversion
object TransparentMacroConversion:
  transparent inline implicit def fromInt(i : Int) : TransparentMacroConversion = ${fromIntInternal}
  def fromIntInternal(using Quotes) : Expr[TransparentMacroConversion] =
    import quotes.reflect.*
    report.error("transparentMacroConversionError")
    '{???}

Test code:

object Test {
  inlineError //error: inlineError 
  transparentInlineError //error: transparentInlineError 
  val i1 : InlineConversion = 1 //error: inlineConversionError
  val i2 : TransparentInlineConversion = 2 //error: transparentInlineConversionError
  macroError //error: macroError 
  transparentMacroError //error: transparentMacroError 
  val i3 : MacroConversion = 3 //error: macroConversionError
  val i4 : TransparentMacroConversion = 4 //Found:    (4 : Int)  Required: TransparentMacroConversion                              
}

Output

transparentMacroError
  transparentMacroError

Found:    (4 : Int)
Required: TransparentMacroConversion
  val i4 : TransparentMacroConversion = 4

Expectation

The last error should be “transparentMacroConversionError”, instead of the type mismatch error. Note: the transparent macro errors are emitted first. Once commented out, we can see the other errors properly emitted.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
oderskycommented, May 12, 2021

By the rules of implicit search an implicit is applicable only if its application can be typed. For a transparent implicit, typing the application means typing the expansion. That explains the behavior, and I think that behavior is reasonable. So I also think there’s nothing to fix here.

0reactions
soronpocommented, May 13, 2021

There is a simple workaround (that was suggested on a different issue by @nicolasstucki and works here), by changing

report.error("transparentMacroConversionError")
'{???}

to

'{compiletime.error("transparentMacroConversionError")}

Given this simple workaround, and given that the brains behind Scala think this is the proper behavior, I’m closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c++ - why doesn't std::any_cast support implicit conversion?
This question is not well posed; implicit conversion to the right type are in principle possible, but disabled.
Read more >
Implicit Conversions - More Details - Scala 3
An implicit conversion, or view, from type S to type T is defined by either: ... A type error reporting the ambiguous conversions...
Read more >
C++ implicit conversions - Fuchsia
Goal & motivation. C/C++ allows converting values between types in ways that may modify the underlying value, for instance due to overflows, ...
Read more >
Implicit Conversions - More Details
An implicit conversion, or view, from type S to type T is defined by either: ... A type error reporting the ambiguous conversions...
Read more >
C++ static code analysis: "explicit" should be used on single ...
"explicit" should be used on single-parameter constructors and conversion operators ... Macros should not be used as replacement to "typdef" and "using".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found