Skip to content

Commit 41f87cc

Browse files
authored
Merge pull request #7726 from dotty-staging/no-alpha-on-ctor
fix #7722 prevent alpha annot on constructor
2 parents 01dc942 + 6557ba3 commit 41f87cc

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,10 @@ class Typer extends Namer
16431643
PrepareInlineable.registerInlineInfo(sym, _ => rhs1)
16441644

16451645
if (sym.isConstructor && !sym.isPrimaryConstructor) {
1646+
val ename = sym.erasedName
1647+
if (ename != sym.name)
1648+
ctx.error(em"@alpha annotation ${'"'}$ename${'"'} may not be used on a constructor", ddef.sourcePos)
1649+
16461650
for (param <- tparams1 ::: vparamss1.flatten)
16471651
checkRefsLegal(param, sym.owner, (name, sym) => sym.is(TypeParam), "secondary constructor")
16481652

tests/neg/7722.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg/7722.scala:2:35 ------------------------------------------------------------------------------------
2+
2 | @scala.annotation.alpha("E") def this() = this(3) // error
3+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
| @alpha annotation "E" may not be used on a constructor

tests/neg/7722.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class A(i:Int){
2+
@scala.annotation.alpha("E") def this() = this(3) // error
3+
}
4+
object O{
5+
def main(args: Array[String]) = {
6+
new A()
7+
}
8+
}

0 commit comments

Comments
 (0)