Skip to content
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

Strangely omitted compileTimeOnly message for Unit companion #17515

Open
som-snytt opened this issue May 15, 2023 · 1 comment · May be fixed by #17516
Open

Strangely omitted compileTimeOnly message for Unit companion #17515

som-snytt opened this issue May 15, 2023 · 1 comment · May be fixed by #17516
Labels
area:annotations area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.2.2

Minimized code

scala> class C { @annotation.compileTimeOnly("non-clonal") override def clone() = null }
// defined class C

scala> C().clone()
-- Error: --------------------------------------------------------------------------------------------------------------
1 |C().clone()
  |^^^^^^^^^
  |non-clonal
1 error found

scala> val u = Unit
-- Error: --------------------------------------------------------------------------------------------------------------
1 |val u = Unit
  |        ^^^^
  |        Reference to object Unit in package scala should not have survived,
  |        it should have been processed and eliminated during expansion of an enclosing macro or term erasure.
1 error found

scala>~ scala
Welcome to Scala 2.13.10 (OpenJDK 64-Bit Server VM, Java 20.0.1).
Type in expressions for evaluation. Or try :help.

scala> val u = Unit
               ^
       error: `Unit` companion object is not allowed in source; instead, use `()` for the unit value

scala>

Expectation

Lowered.

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 15, 2023
@som-snytt
Copy link
Contributor Author

som-snytt commented May 15, 2023

It doesn't recognize annot.args(0) as a constant.

Some(TypeApply(Select(Literal(Constant(`Unit` companion object is not allowed in source; instead, use `()` for the unit value)),asInstanceOf),List(TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class scala)),object Predef),type String)])))

Perhaps it's because only some annotations were converted to ConstantAnnotation at scala/scala#9336.

That was due to auxiliary constructors, as commented on deprecatedNames.

So for example

Welcome to Scala 3.3.1-RC1-bin-SNAPSHOT-git-22b2259 (20.0.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> "abc".forall(f = (_: Char) => true)
-- Error: --------------------------------------------------------------------------------------------------------------
1 |"abc".forall(f = (_: Char) => true)
  |             ^^^^^^^^^^^^^^^^^^^^^
  |             method forall in class StringOps: (p: Char => Boolean): Boolean does not have a parameter f
1 error found

instead of

scala> "abc".forall(f = (_: Char) => true)
                      ^
       warning: the parameter name f is deprecated (since 2.13.3): use p instead
val res1: Boolean = true

for @deprecatedName.

The famous last words at scala/scala#9463 (comment)

Honestly no idea, I never got what ConstantAnnotation was for and Dotty doesn't treat it specially.

Not immediately obvious where the cast comes from, but maybe Scala 3 can drill past asInstanceOf in its search for an arg.

Also erasure should use annot.argumentConstantString and not convert toString.

@som-snytt som-snytt linked a pull request May 15, 2023 that will close this issue
@WojciechMazur WojciechMazur added area:annotations area:reporting Error reporting including formatting, implicit suggestions, etc and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:annotations area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants