transparent implicit conversion macro not emitting the proper error
See original GitHub issueAmong 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:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
There is a simple workaround (that was suggested on a different issue by @nicolasstucki and works here), by changing
to
Given this simple workaround, and given that the brains behind Scala think this is the proper behavior, I’m closing this issue.