Skip to content

Commit ebb4799

Browse files
committed
Fix scala#6150: Emit error when calling Scala 2 macro
1 parent 2364270 commit ebb4799

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

compiler/src/dotty/tools/dotc/profile/Profiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ object ConsoleProfileReporter extends ProfileReporter {
228228
}
229229

230230
override def reportGc(data: GcEventData): Unit = {
231-
println(f"Profiler GC reported ${data.gcEndMillis - data.gcStartMillis}ms")
231+
println(s"Profiler GC reported ${data.gcEndMillis - data.gcStartMillis}ms")
232232
}
233233
}
234234

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,6 +2655,10 @@ 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)) {
2659+
ctx.error("Scala 2 macro cannot be used in Dotty. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html", tree.sourcePos)
2660+
tree
2661+
}
26582662
else if (tree.tpe <:< pt) {
26592663
if (pt.hasAnnotation(defn.InlineParamAnnot))
26602664
checkInlineConformant(tree, isFinal = false, "argument to inline parameter")

compiler/test/dotty/tools/backend/jvm/AsmNode.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ sealed trait AsmNode[+T] {
1515
def attrs: List[Attribute]
1616
def visibleAnnotations: List[AnnotationNode]
1717
def invisibleAnnotations: List[AnnotationNode]
18-
def characteristics = f"$name%15s $desc%-30s$accessString$sigString"
19-
def erasedCharacteristics = f"$name%15s $desc%-30s$accessString"
18+
def characteristics = "%15s %-30s%s%s".format(name, desc, accessString, sigString)
19+
def erasedCharacteristics = "%15s %-30s%s".format(name, desc, accessString)
2020

2121
private def accessString = if (access == 0) "" else " " + Modifier.toString(access)
2222
private def sigString = if (signature == null) "" else " " + signature

project/Build.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,12 @@ object Build {
549549
IO.delete(trgDir)
550550
IO.createDirectory(trgDir)
551551
IO.unzip(scalaJSIRSourcesJar, trgDir)
552+
553+
// Remove f interpolator macro call to avoid its expansion while compiling the compiler and the implementation of the f macro
554+
val utilsFile = trgDir / "org/scalajs/ir/Utils.scala"
555+
val patchedSource = IO.read(utilsFile).replace("""f"\\u$c%04x"""", """"\\u%04x".format(c)""")
556+
IO.write(utilsFile, patchedSource)
557+
552558
(trgDir ** "*.scala").get.toSet
553559
} (Set(scalaJSIRSourcesJar)).toSeq
554560
}.taskValue,

0 commit comments

Comments
 (0)