Skip to content

Make Phantom.assume return type an ExprType #2713

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
Jun 8, 2017
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ class Definitions {

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

cls
}
Expand Down
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,14 @@ object Erasure extends TypeTestsCasts{
}
}

recur(typed(tree.qualifier, AnySelectionProto))
if (tree.symbol eq defn.Phantom_assume) PhantomErasure.erasedAssume
else recur(typed(tree.qualifier, AnySelectionProto))
}

override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): tpd.Tree =
if (tree.symbol eq defn.Phantom_assume) PhantomErasure.erasedAssume
else super.typedIdent(tree, pt)

override def typedThis(tree: untpd.This)(implicit ctx: Context): Tree =
if (tree.symbol == ctx.owner.lexicallyEnclosingClass || tree.symbol.isStaticOwner) promote(tree)
else {
Expand Down Expand Up @@ -456,8 +461,6 @@ object Erasure extends TypeTestsCasts{
val Apply(fun, args) = tree
if (fun.symbol == defn.cbnArg)
typedUnadapted(args.head, pt)
else if (fun.symbol eq defn.Phantom_assume)
PhantomErasure.erasedAssume
else typedExpr(fun, FunProto(args, pt, this)) match {
case fun1: Apply => // arguments passed in prototype were already passed
fun1
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/phantom-assume-1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Boo extends Phantom {
type BooAny = this.Any
def assume1: BooAny = assume() // error: method assume in trait Phantom does not take parameters
}
Empty file.
17 changes: 17 additions & 0 deletions tests/run/phantom-assume-1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

object Test {
import Boo._

def main(args: Array[String]): Unit = {
Boo.assume1
Boo.assume2
Boo.assume3
}
}

object Boo extends Phantom {
type BooAny = this.Any
def assume1: BooAny = assume
def assume2: BooAny = this.assume
def assume3: BooAny = Boo.assume
}