Skip to content

fix #7722 prevent alpha annot on constructor #7726

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

Merged
merged 1 commit into from
Dec 12, 2019
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
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,10 @@ class Typer extends Namer
PrepareInlineable.registerInlineInfo(sym, _ => rhs1)

if (sym.isConstructor && !sym.isPrimaryConstructor) {
val ename = sym.erasedName
if (ename != sym.name)
ctx.error(em"@alpha annotation ${'"'}$ename${'"'} may not be used on a constructor", ddef.sourcePos)

for (param <- tparams1 ::: vparamss1.flatten)
checkRefsLegal(param, sym.owner, (name, sym) => sym.is(TypeParam), "secondary constructor")

Expand Down
4 changes: 4 additions & 0 deletions tests/neg/7722.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/7722.scala:2:35 ------------------------------------------------------------------------------------
2 | @scala.annotation.alpha("E") def this() = this(3) // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| @alpha annotation "E" may not be used on a constructor
8 changes: 8 additions & 0 deletions tests/neg/7722.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class A(i:Int){
@scala.annotation.alpha("E") def this() = this(3) // error
}
object O{
def main(args: Array[String]) = {
new A()
}
}