Skip to content
Merged
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object Annotations {
if (i < args.length) Some(args(i)) else None
}
def argumentConstant(i: Int)(using Context): Option[Constant] =
for (case ConstantType(c) <- argument(i) map (_.tpe.widenTermRefExpr.normalized)) yield c
for case ConstantType(c) <- argument(i).map(stripCast(_).tpe.widenTermRefExpr.normalized) yield c

def argumentConstantString(i: Int)(using Context): Option[String] =
for (case Constant(s: String) <- argumentConstant(i)) yield s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,14 +1002,14 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
/** Read an annotation argument, which is pickled either
* as a Constant or a Tree.
*/
protected def readAnnotArg(i: Int)(using Context): untpd.Tree = untpd.TypedSplice(bytes(index(i)) match
protected def readAnnotArg(i: Int)(using Context): untpd.Tree = untpd.TypedSplice:
bytes(index(i)) match
case TREE => at(i, () => readTree())
case _ => at(i, () =>
readConstant() match
case c: Constant => Literal(c)
case tp: TermRef => ref(tp)
)
)

/** Read a ClassfileAnnotArg (argument to a classfile annotation)
*/
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -561,15 +561,15 @@ object Erasure {
report.error(msg, tree.srcPos)
tree.symbol.getAnnotation(defn.CompileTimeOnlyAnnot) match
case Some(annot) =>
val message = annot.argumentConstant(0) match
case Some(c) =>
val message = annot.argumentConstantString(0) match
case Some(msg) =>
val addendum = tree match
case tree: RefTree
if tree.symbol == defn.Compiletime_deferred && tree.name != nme.deferred =>
i".\nNote that `deferred` can only be used under its own name when implementing a given in a trait; `${tree.name}` is not accepted."
case _ =>
""
(c.stringValue ++ addendum).toMessage
(msg + addendum).toMessage
case _ =>
em"""Reference to ${tree.symbol.showLocated} should not have survived,
|it should have been processed and eliminated during expansion of an enclosing macro or term erasure."""
Expand Down
14 changes: 14 additions & 0 deletions tests/neg/no-unit.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- [E190] Potential Issue Warning: tests/neg/no-unit.scala:7:2 ---------------------------------------------------------
7 | Unit // error
| ^^^^
| Discarded non-Unit value of type object Unit. Add `: Unit` to discard silently.
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg/no-unit.scala:1:8 ----------------------------------------------------------------------------------
1 |val u = Unit // error
| ^^^^
| `Unit` companion object is not allowed in source; instead, use `()` for the unit value
-- Error: tests/neg/no-unit.scala:7:2 ----------------------------------------------------------------------------------
7 | Unit // error
| ^^^^
| `Unit` companion object is not allowed in source; instead, use `()` for the unit value
7 changes: 7 additions & 0 deletions tests/neg/no-unit.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
val u = Unit // error

inline def a(inline f: Unit ?=> Unit): Unit = f(using ())

def s5bug = a:
print(2)
Unit // error
2 changes: 1 addition & 1 deletion tests/neg/serialversionuid-not-const.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@SerialVersionUID(13l.toLong) class C1 extends Serializable // OK because toLong is constant-folded
@SerialVersionUID(13l) class C2 extends Serializable // OK
@SerialVersionUID(13.asInstanceOf[Long]) class C3 extends Serializable // error
@SerialVersionUID(13.asInstanceOf[Long]) class C3 extends Serializable // OK was error
@SerialVersionUID(Test.bippy) class C4 extends Serializable // error

object Test {
Expand Down
Loading