Skip to content

Commit d5840fc

Browse files
committed
Fix #6150: Emit error when calling Scala 2 macro
1 parent a25163d commit d5840fc

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
@@ -2753,6 +2753,10 @@ class Typer extends Namer
27532753
tree.tpe <:< wildApprox(pt)
27542754
readaptSimplified(Inliner.inlineCall(tree, pt))
27552755
}
2756+
else if (tree.symbol.is(Macro, butNot = Inline)) {
2757+
ctx.error("Scala 2 macro cannot be used in Dotty. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html", tree.sourcePos)
2758+
tree
2759+
}
27562760
else if (tree.tpe <:< pt) {
27572761
if (pt.hasAnnotation(defn.InlineParamAnnot))
27582762
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
@@ -568,6 +568,12 @@ object Build {
568568
IO.delete(trgDir)
569569
IO.createDirectory(trgDir)
570570
IO.unzip(scalaJSIRSourcesJar, trgDir)
571+
572+
// Remove f interpolator macro call to avoid its expansion while compiling the compiler and the implementation of the f macro
573+
val utilsFile = trgDir / "org/scalajs/ir/Utils.scala"
574+
val patchedSource = IO.read(utilsFile).replace("""f"\\u$c%04x"""", """"\\u%04x".format(c)""")
575+
IO.write(utilsFile, patchedSource)
576+
571577
(trgDir ** "*.scala").get.toSet
572578
} (Set(scalaJSIRSourcesJar)).toSeq
573579
}.taskValue,

0 commit comments

Comments
 (0)