Skip to content

Commit 0030e1e

Browse files
committed
Allow dual Scala 2/3 in non-experimental scopes
1 parent 7b57e72 commit 0030e1e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

compiler/src/dotty/tools/dotc/transform/PruneErasedDefs.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
5555
tree
5656

5757
def checkErasedInExperimental(sym: Symbol)(using Context): Unit =
58-
if sym.is(Erased) && sym != defn.Compiletime_erasedValue && !sym.isInExperimentalScope then
58+
// Make an exception for Scala 2 experimental macros to allow dual Scala 2/3 macros under non experimental mode
59+
if sym.is(Erased, butNot = Macro) && sym != defn.Compiletime_erasedValue && !sym.isInExperimentalScope then
5960
Feature.checkExperimentalFeature("erased", sym.sourcePos)
6061
}
6162

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// src-2/MacroImpl.scala
2+
trait Context {
3+
object universe {
4+
type Literal
5+
}
6+
}
7+
8+
class MacroImpl(val c: Context) {
9+
import c.universe.*
10+
def mono: Literal = ???
11+
}
12+
13+
// src-3/Macros.scala
14+
import scala.language.experimental.macros
15+
16+
object Macros {
17+
18+
object Bundles {
19+
def mono: Unit = macro MacroImpl.mono
20+
inline def mono: Unit = ${ Macros3.monoImpl }
21+
}
22+
23+
object Macros3 {
24+
def monoImpl(using quoted.Quotes) = '{()}
25+
}
26+
27+
}

0 commit comments

Comments
 (0)