Skip to content

Commit efd230d

Browse files
committed
Fix Scala 2 Macro check
Previously we checked for `Macro | Scala2x` but the `Scala2x` was on its owner
1 parent 2f0d72a commit efd230d

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,6 @@ object Flags {
661661
/** Is a default parameter in Scala 2*/
662662
final val DefaultParameter: FlagConjunction = allOf(Param, DefaultParameterized)
663663

664-
/** A Scala 2 Macro */
665-
final val Scala2Macro: FlagConjunction = allOf(Macro, Scala2x)
666-
667664
/** A trait that does not need to be initialized */
668665
final val NoInitsTrait: FlagConjunction = allOf(Trait, NoInits)
669666

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,9 @@ object SymDenotations {
807807
// we need an inline flag on them only do that
808808
// reduceProjection gets access to their rhs
809809

810+
/** Is this a Scala 2 macro */
811+
final def isScala2Macro(implicit ctx: Context): Boolean = is(Macro) && symbol.owner.is(Scala2x)
812+
810813
/** An erased value or an inline method, excluding @forceInline annotated methods.
811814
* The latter have to be kept around to get to parity with Scala.
812815
* This is necessary at least until we have full bootstrap. Right now

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ object RefChecks {
400400
overrideError("is an extension method, cannot override a normal method")
401401
} else if (other.is(Extension) && !member.is(Extension)) { // (1.9.2)
402402
overrideError("is a normal method, cannot override an extension method")
403-
} else if ((member.isInlineMethod || member.is(Scala2Macro)) && other.is(Deferred) &&
403+
} else if ((member.isInlineMethod || member.isScala2Macro) && other.is(Deferred) &&
404404
member.extendedOverriddenSymbols.forall(_.is(Deferred))) { // (1.10)
405405
overrideError("is an inline method, must override at least one concrete method")
406-
} else if (other.is(Scala2Macro) && !member.is(Scala2Macro)) { // (1.11)
406+
} else if (other.isScala2Macro && !member.isScala2Macro) { // (1.11)
407407
overrideError("cannot be used here - only Scala-2 macros can override Scala-2 macros")
408408
} else if (!compatibleTypes(memberTp(self), otherTp(self)) &&
409409
!compatibleTypes(memberTp(upwardsSelf), otherTp(upwardsSelf))) {

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2655,7 +2655,7 @@ class Typer extends Namer
26552655
tree.tpe <:< wildApprox(pt)
26562656
readaptSimplified(Inliner.inlineCall(tree, pt))
26572657
}
2658-
else if (tree.symbol.is(Macro, butNot = Inline)) {
2658+
else if (tree.symbol.isScala2Macro) {
26592659
if (ctx.settings.XignoreScala2Macros.value) {
26602660
ctx.warning("Scala 2 macro cannot be used in Dotty. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html", tree.sourcePos)
26612661
tree

tests/neg/override-scala2-macro.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<56..56> in override-scala2-macro.scala
2+
error overriding method f in class StringContext of type [A >: Any](args: Seq[A]): String;
3+
method f of type [A >: Any](args: Seq[A]): String cannot be used here - only Scala-2 macros can override Scala-2 macros

tests/neg/override-scala2-macro.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo extends StringContext {
2+
override inline def f[A >: Any](args: A*): String = ??? // error
3+
}

0 commit comments

Comments
 (0)