Skip to content

Accommodate adapted Scala 2 annotation value #17516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
13 changes: 9 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import core.Scopes.newScopeWith
import core.Decorators.*
import core.Constants.*
import core.Definitions.*
import core.Annotations.BodyAnnotation
import core.Annotations.{Annotation, BodyAnnotation}
import typer.NoChecking
import inlines.Inlines
import typer.ProtoTypes.*
Expand Down Expand Up @@ -550,6 +550,11 @@ object Erasure {
* - Java statics and packages can only be used in selections.
*/
private def checkNotErased(tree: Tree)(using Context): tree.type =
extension (annot: Annotation) def argumentAdaptedConstantString(i: Int)(using Context): Option[String] =
annot.argument(i) match
case Some(Literal(Constant(s: String))) => Some(s)
case Some(TypeApply(Select(Literal(Constant(s: String)), nme.asInstanceOf_), _)) => Some(s)
case _ => None
if !ctx.mode.is(Mode.Type) then
if isErased(tree) then
val msg =
Expand All @@ -562,15 +567,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).orElse(annot.argumentAdaptedConstantString(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
4 changes: 4 additions & 0 deletions tests/neg/no-unit.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- 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
1 change: 1 addition & 0 deletions tests/neg/no-unit.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val u = Unit // error
Loading