Skip to content

Commit

Permalink
Disallow phantom var
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed May 9, 2017
1 parent 5db4230 commit 7f0c087
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 73 deletions.
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/FirstTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ class FirstTransform extends MiniPhaseTransform with InfoTransformer with Annota
}

override def transformValDef(vdef: tpd.ValDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
if (vdef.symbol.hasAnnotation(defn.VolatileAnnot) && vdef.tpt.tpe.isPhantom)
ctx.error("Phantom fields can not be @volatile", vdef.pos)
if (vdef.tpt.tpe.isPhantom) {
if (vdef.symbol.is(Mutable)) ctx.error("var fields can not have Phantom types", vdef.pos)

This comment has been minimized.

Copy link
@smarter

smarter May 9, 2017

Member

can not -> cannot

else if (vdef.symbol.hasAnnotation(defn.VolatileAnnot)) ctx.error("Phantom fields can not be @volatile", vdef.pos)
}
vdef
}

Expand Down
8 changes: 8 additions & 0 deletions tests/neg/phantom-var.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

class Foo {
var foo = Boo.boo // error: var fields can not have Phantom types
}

object Boo extends Phantom {
def boo = assume
}
3 changes: 2 additions & 1 deletion tests/neg/phantom-volitile.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

class Foo {
@volatile var foo = Boo.boo // error
@volatile var foo1 = Boo.boo // error: var fields can not have Phantom types
@volatile val foo2 = Boo.boo // error: Phantom fields can not be @volatile
}

object Boo extends Phantom {
Expand Down
3 changes: 0 additions & 3 deletions tests/run/phantom-var-2.check

This file was deleted.

35 changes: 0 additions & 35 deletions tests/run/phantom-var-2.scala

This file was deleted.

2 changes: 0 additions & 2 deletions tests/run/phantom-var.check

This file was deleted.

30 changes: 0 additions & 30 deletions tests/run/phantom-var.scala

This file was deleted.

0 comments on commit 7f0c087

Please sign in to comment.