Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,6 @@ object SymDenotations {
/** Is this a Scala 2 macro defined */
final def isScala2MacroInScala3(using Context): Boolean =
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
// Consider the macros of StringContext as plain Scala 2 macros when
// compiling the standard library with Dotty.
// This should be removed on Scala 3.x
&& owner.ne(defn.StringContextClass)

/** An erased value or an erased inline method or field */
def isErased(using Context): Boolean =
Expand Down
10 changes: 1 addition & 9 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -672,16 +672,8 @@ class TreeUnpickler(reader: TastyReader,
if sym.owner.isClass then newLocalDummy(sym.owner) else sym.owner
sym.annotations = annotFns.map(_(annotOwner))
if sym.isOpaqueAlias then sym.setFlag(Deferred)
val isScala2MacroDefinedInScala3 = flags.is(Macro, butNot = Inline) && flags.is(Erased)
ctx.owner match {
case cls: ClassSymbol if !isScala2MacroDefinedInScala3 || cls == defn.StringContextClass =>
// Enter all members of classes that are not Scala 2 macros.
//
// For `StringContext`, enter `s`, `f` and `raw`
// These definitions will be entered when defined in Scala 2. It is fine to enter them
// as they are intrinsic macros and are specially handled by the compiler.
// Dual macro definitions will not work on `StringContext` as we would enter the symbol twice.
// But dual macros will never be needed for those definitions due to their intinsic nature.
case cls: ClassSymbol if !sym.isScala2MacroInScala3 =>
cls.enter(sym)
case _ =>
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
andAlso = defn.NonBeanParamAccessorAnnots)
else
sym.keepAnnotationsCarrying(thisPhase, Set(defn.GetterMetaAnnot, defn.FieldMetaAnnot), orNoneOf = defn.NonBeanMetaAnnots)
if sym.isScala2Macro && !ctx.settings.XignoreScala2Macros.value &&
sym != defn.StringContext_raw &&
sym != defn.StringContext_f &&
sym != defn.StringContext_s then
if sym.isScala2Macro && !ctx.settings.XignoreScala2Macros.value then
if !sym.owner.unforcedDecls.exists(p => !p.isScala2Macro && p.name == sym.name && p.signature == sym.signature)
// Allow scala.reflect.materializeClassTag to be able to compile scala/reflect/package.scala
// This should be removed on Scala 3.x
Expand Down
6 changes: 1 addition & 5 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4740,11 +4740,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
val inlined = Inlines.inlineCall(tree)
if ((inlined ne tree) && errorCount == ctx.reporter.errorCount) readaptSimplified(inlined)
else inlined
else if (tree.symbol.isScala2Macro &&
// `raw`, `f` and `s` are eliminated by the StringInterpolatorOpt phase
tree.symbol != defn.StringContext_raw &&
tree.symbol != defn.StringContext_f &&
tree.symbol != defn.StringContext_s)
else if (tree.symbol.isScala2Macro)
if (ctx.settings.XignoreScala2Macros.value) {
report.warning("Scala 2 macro cannot be used in Dotty, this call will crash at runtime. See https://docs.scala-lang.org/scala3/reference/dropped-features/macros.html", tree.srcPos.startPos)
Throw(New(defn.MatchErrorClass.typeRef, Literal(Constant(s"Reached unexpanded Scala 2 macro call to ${tree.symbol.showFullName} compiled with -Xignore-scala2-macros.")) :: Nil))
Expand Down
6 changes: 3 additions & 3 deletions library/src/scala/StringContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ case class StringContext(parts: String*) {
* @note The Scala compiler may replace a call to this method with an equivalent, but more efficient,
* use of a StringBuilder.
*/
def s(args: Any*): String = macro ??? // fasttracked to scala.tools.reflect.FastStringInterpolator::interpolateS
def s(args: Any*): String = ??? // fasttracked to scala.tools.reflect.FastStringInterpolator::interpolateS
object s {
/** The simple string matcher.
*
Expand Down Expand Up @@ -154,7 +154,7 @@ case class StringContext(parts: String*) {
* @note The Scala compiler may replace a call to this method with an equivalent, but more efficient,
* use of a StringBuilder.
*/
def raw(args: Any*): String = macro ??? // fasttracked to scala.tools.reflect.FastStringInterpolator::interpolateRaw
def raw(args: Any*): String = ??? // fasttracked to scala.tools.reflect.FastStringInterpolator::interpolateRaw

@deprecated("Use the static method StringContext.standardInterpolator instead of the instance method", "2.13.0")
def standardInterpolator(process: String => String, args: Seq[Any]): String = scStandardInterpolator(process, args, parts)
Expand Down Expand Up @@ -194,7 +194,7 @@ case class StringContext(parts: String*) {
* 2. Any `%` characters not in formatting positions must begin one of the conversions
* `%%` (the literal percent) or `%n` (the platform-specific line separator).
*/
def f[A >: Any](args: A*): String = macro ??? // fasttracked to scala.tools.reflect.FormatInterpolator::interpolateF
def f[A >: Any](args: A*): String = ??? // fasttracked to scala.tools.reflect.FormatInterpolator::interpolateF
}

object StringContext {
Expand Down
8 changes: 4 additions & 4 deletions tests/neg/override-scala2-macro.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- [E164] Declaration Error: tests/neg/override-scala2-macro.scala:2:22 ------------------------------------------------
2 | override inline def f[A >: Any](args: A*): String = ??? // error
-- [E164] Declaration Error: tests/neg/override-scala2-macro/B_2.scala:2:22 --------------------------------------------
2 | override inline def foo: Unit = ??? // error
| ^
|error overriding method f in class StringContext of type [A >: Any](args: Seq[A]): String;
| method f of type [A >: Any](args: Seq[A]): String cannot be used here - only Scala-2 macros can override Scala-2 macros
| error overriding method foo in class A of type => Unit;
| method foo of type => Unit cannot be used here - only Scala-2 macros can override Scala-2 macros
3 changes: 0 additions & 3 deletions tests/neg/override-scala2-macro.scala

This file was deleted.

5 changes: 5 additions & 0 deletions tests/neg/override-scala2-macro/A_1_c2.13.16.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import scala.language.experimental.macros

class A {
def foo: Unit = macro ???
}
3 changes: 3 additions & 0 deletions tests/neg/override-scala2-macro/B_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class B extends A {
override inline def foo: Unit = ??? // error
}
Loading
Loading