Skip to content

Commit 1cb905f

Browse files
committed
Accommodate Scala 2 annotation value
1 parent a115c8d commit 1cb905f

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,14 +1002,14 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
10021002
/** Read an annotation argument, which is pickled either
10031003
* as a Constant or a Tree.
10041004
*/
1005-
protected def readAnnotArg(i: Int)(using Context): untpd.Tree = untpd.TypedSplice(bytes(index(i)) match
1005+
protected def readAnnotArg(i: Int)(using Context): untpd.Tree = untpd.TypedSplice:
1006+
bytes(index(i)) match
10061007
case TREE => at(i, () => readTree())
10071008
case _ => at(i, () =>
10081009
readConstant() match
10091010
case c: Constant => Literal(c)
10101011
case tp: TermRef => ref(tp)
10111012
)
1012-
)
10131013

10141014
/** Read a ClassfileAnnotArg (argument to a classfile annotation)
10151015
*/

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ object Erasure {
386386
assert(mt.paramInfos.isEmpty, i"bad adapt for $tree: $mt")
387387
adaptToType(tree.appliedToNone, pt)
388388
case tpw =>
389-
if (pt.isInstanceOf[ProtoType] || tree.tpe <:< pt)
389+
if pt.isInstanceOf[ProtoType] || tree.tpe <:< pt.underlyingIfProxy.orElse(pt) then
390390
tree
391391
else if (tpw.isErasedValueType)
392392
if (pt.isErasedValueType) then
@@ -562,15 +562,15 @@ object Erasure {
562562
report.error(msg, tree.srcPos)
563563
tree.symbol.getAnnotation(defn.CompileTimeOnlyAnnot) match
564564
case Some(annot) =>
565-
val message = annot.argumentConstant(0) match
566-
case Some(c) =>
565+
val message = annot.argumentConstantString(0) match
566+
case Some(msg) =>
567567
val addendum = tree match
568568
case tree: RefTree
569569
if tree.symbol == defn.Compiletime_deferred && tree.name != nme.deferred =>
570570
i".\nNote that `deferred` can only be used under its own name when implementing a given in a trait; `${tree.name}` is not accepted."
571571
case _ =>
572572
""
573-
(c.stringValue ++ addendum).toMessage
573+
(msg + addendum).toMessage
574574
case _ =>
575575
em"""Reference to ${tree.symbol.showLocated} should not have survived,
576576
|it should have been processed and eliminated during expansion of an enclosing macro or term erasure."""

tests/neg/no-unit.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg/no-unit.scala:1:8 ----------------------------------------------------------------------------------
2+
1 |val u = Unit // error
3+
| ^^^^
4+
| `Unit` companion object is not allowed in source; instead, use `()` for the unit value

tests/neg/no-unit.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val u = Unit // error

0 commit comments

Comments
 (0)