Skip to content

Commit 4f3429c

Browse files
Backport "fix scala 2 macros in traits with type parameters" to LTS (#20646)
Backports #18663 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 70ecf1a + 26336ef commit 4f3429c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/SymDenotations.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ object SymDenotations {
10301030

10311031
/** Is this a Scala 2 macro defined */
10321032
final def isScala2MacroInScala3(using Context): Boolean =
1033-
is(Macro, butNot = Inline) && is(Erased)
1033+
is(Macro, butNot = Inline) && flagsUNSAFE.is(Erased) // flag is set initially for macros - we check if it's a scala 2 macro before completing the type constructor so do not force the info to check the flag
10341034
// Consider the macros of StringContext as plain Scala 2 macros when
10351035
// compiling the standard library with Dotty.
10361036
// This should be removed on Scala 3.x

Diff for: tests/pos-macros/i16630.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.language.experimental.macros
2+
import scala.quoted.{Quotes, Expr, Type}
3+
4+
trait TraitWithTypeParam[A]:
5+
inline def foo: Option[A] = ${ MacrosImpl.fooImpl[A] }
6+
def foo: Option[A] = macro MacrosImpl.compatFooImpl[A]
7+
8+
object MacrosImpl:
9+
def fooImpl[A: Type](using quotes: Quotes): Expr[Option[A]] = ???
10+
def compatFooImpl[A: c.WeakTypeTag](c: Context): c.Tree = ???
11+
12+
trait Context:
13+
type WeakTypeTag[A]
14+
type Tree

0 commit comments

Comments
 (0)