Skip to content

Commit 100d672

Browse files
committed
Make Phantom.assume return type an ExprType
1 parent 1f7af24 commit 100d672

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ class Definitions {
10101010

10111011
val any = enterCompleteClassSymbol(cls, tpnme.Any, Protected | Final | NoInitsTrait, Nil)
10121012
val nothing = enterCompleteClassSymbol(cls, tpnme.Nothing, Protected | Final | NoInitsTrait, List(any.typeRef))
1013-
enterMethod(cls, nme.assume_, MethodType(Nil, nothing.typeRef), Protected | Final | Method)
1013+
enterMethod(cls, nme.assume_, ExprType(nothing.typeRef), Protected | Final | Method)
10141014

10151015
cls
10161016
}

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,14 @@ object Erasure extends TypeTestsCasts{
411411
}
412412
}
413413

414-
recur(typed(tree.qualifier, AnySelectionProto))
414+
if (tree.symbol eq defn.Phantom_assume) PhantomErasure.erasedAssume
415+
else recur(typed(tree.qualifier, AnySelectionProto))
415416
}
416417

418+
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): tpd.Tree =
419+
if (tree.symbol eq defn.Phantom_assume) PhantomErasure.erasedAssume
420+
else super.typedIdent(tree, pt)
421+
417422
override def typedThis(tree: untpd.This)(implicit ctx: Context): Tree =
418423
if (tree.symbol == ctx.owner.lexicallyEnclosingClass || tree.symbol.isStaticOwner) promote(tree)
419424
else {
@@ -456,8 +461,6 @@ object Erasure extends TypeTestsCasts{
456461
val Apply(fun, args) = tree
457462
if (fun.symbol == defn.cbnArg)
458463
typedUnadapted(args.head, pt)
459-
else if (fun.symbol eq defn.Phantom_assume)
460-
PhantomErasure.erasedAssume
461464
else typedExpr(fun, FunProto(args, pt, this)) match {
462465
case fun1: Apply => // arguments passed in prototype were already passed
463466
fun1

tests/neg/phantom-assume-1.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Boo extends Phantom {
2+
type BooAny = this.Any
3+
def assume1: BooAny = assume() // error: method assume in trait Phantom does not take parameters
4+
}

tests/run/phantom-assume-1.check

Whitespace-only changes.

tests/run/phantom-assume-1.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
object Test {
3+
import Boo._
4+
5+
def main(args: Array[String]): Unit = {
6+
Boo.assume1
7+
Boo.assume2
8+
Boo.assume3
9+
}
10+
}
11+
12+
object Boo extends Phantom {
13+
type BooAny = this.Any
14+
def assume1: BooAny = assume
15+
def assume2: BooAny = this.assume
16+
def assume3: BooAny = Boo.assume
17+
}

0 commit comments

Comments
 (0)