Skip to content

Commit 95e9d55

Browse files
committed
Regression test and simplify
1 parent 3bea2f3 commit 95e9d55

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,15 @@ object Erasure {
560560
report.error(msg, tree.srcPos)
561561
tree.symbol.getAnnotation(defn.CompileTimeOnlyAnnot) match
562562
case Some(annot) =>
563-
val message = annot.argumentConstant(0) match
564-
case Some(c) =>
563+
val message = annot.argumentConstantString(0) match
564+
case Some(msg) =>
565565
val addendum = tree match
566566
case tree: RefTree
567567
if tree.symbol == defn.Compiletime_deferred && tree.name != nme.deferred =>
568568
i".\nNote that `deferred` can only be used under its own name when implementing a given in a trait; `${tree.name}` is not accepted."
569569
case _ =>
570570
""
571-
(c.stringValue ++ addendum).toMessage
571+
(msg + addendum).toMessage
572572
case _ =>
573573
em"""Reference to ${tree.symbol.showLocated} should not have survived,
574574
|it should have been processed and eliminated during expansion of an enclosing macro or term erasure."""

tests/neg/no-unit.check

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- [E190] Potential Issue Warning: tests/neg/no-unit.scala:7:2 ---------------------------------------------------------
2+
7 | Unit // error
3+
| ^^^^
4+
| Discarded non-Unit value of type object Unit. Add `: Unit` to discard silently.
5+
|
6+
| longer explanation available when compiling with `-explain`
7+
-- Error: tests/neg/no-unit.scala:1:8 ----------------------------------------------------------------------------------
8+
1 |val u = Unit // error
9+
| ^^^^
10+
| `Unit` companion object is not allowed in source; instead, use `()` for the unit value
11+
-- Error: tests/neg/no-unit.scala:7:2 ----------------------------------------------------------------------------------
12+
7 | Unit // error
13+
| ^^^^
14+
| `Unit` companion object is not allowed in source; instead, use `()` for the unit value

tests/neg/no-unit.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
val u = Unit // error
2+
3+
inline def a(inline f: Unit ?=> Unit): Unit = f(using ())
4+
5+
def s5bug = a:
6+
print(2)
7+
Unit // error

0 commit comments

Comments
 (0)