-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #1503: be more careful where to insert apply #1522
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -927,15 +927,18 @@ object Types { | |
def narrow(implicit ctx: Context): TermRef = | ||
TermRef(NoPrefix, ctx.newSkolem(this)) | ||
|
||
/** Useful for diagnsotics: The underlying type if this type is a type proxy, | ||
/** Useful for diagnostics: The underlying type if this type is a type proxy, | ||
* otherwise NoType | ||
*/ | ||
def underlyingIfProxy(implicit ctx: Context) = this match { | ||
case this1: TypeProxy => this1.underlying | ||
case _ => NoType | ||
} | ||
|
||
// ----- Normalizing typerefs over refined types ---------------------------- | ||
/** If this is a FunProto or PolyProto, WildcardType, otherwise this */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also not entirely sure why using |
||
def notApplied: Type = this | ||
|
||
// ----- Normalizing typerefs over refined types ---------------------------- | ||
|
||
/** If this normalizes* to a refinement type that has a refinement for `name` (which might be followed | ||
* by other refinements), and the refined info is a type alias, return the alias, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -572,7 +572,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |
def typedBlock(tree: untpd.Block, pt: Type)(implicit ctx: Context) = track("typedBlock") { | ||
val exprCtx = index(tree.stats) | ||
val stats1 = typedStats(tree.stats, ctx.owner) | ||
val expr1 = typedExpr(tree.expr, pt)(exprCtx) | ||
val ept = if (tree.isInstanceOf[untpd.InfixOpBlock]) pt else pt.notApplied | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment explaining why |
||
val expr1 = typedExpr(tree.expr, ept)(exprCtx) | ||
ensureNoLocalRefs( | ||
assignType(cpy.Block(tree)(stats1, expr1), stats1, expr1), pt, localSyms(stats1)) | ||
} | ||
|
@@ -619,8 +620,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |
|
||
def typedIf(tree: untpd.If, pt: Type)(implicit ctx: Context) = track("typedIf") { | ||
val cond1 = typed(tree.cond, defn.BooleanType) | ||
val thenp1 = typed(tree.thenp, pt) | ||
val elsep1 = typed(tree.elsep orElse (untpd.unitLiteral withPos tree.pos), pt) | ||
val thenp1 = typed(tree.thenp, pt.notApplied) | ||
val elsep1 = typed(tree.elsep orElse (untpd.unitLiteral withPos tree.pos), pt.notApplied) | ||
val thenp2 :: elsep2 :: Nil = harmonize(thenp1 :: elsep1 :: Nil) | ||
assignType(cpy.If(tree)(cond1, thenp2, elsep2), thenp2, elsep2) | ||
} | ||
|
@@ -793,7 +794,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |
val selType = widenForMatchSelector( | ||
fullyDefinedType(sel1.tpe, "pattern selector", tree.pos)) | ||
|
||
val cases1 = typedCases(tree.cases, selType, pt) | ||
val cases1 = typedCases(tree.cases, selType, pt.notApplied) | ||
val cases2 = harmonize(cases1).asInstanceOf[List[CaseDef]] | ||
assignType(cpy.Match(tree)(sel1, cases2), cases2) | ||
} | ||
|
@@ -920,8 +921,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |
} | ||
|
||
def typedTry(tree: untpd.Try, pt: Type)(implicit ctx: Context): Try = track("typedTry") { | ||
val expr1 = typed(tree.expr, pt) | ||
val cases1 = typedCases(tree.cases, defn.ThrowableType, pt) | ||
val expr1 = typed(tree.expr, pt.notApplied) | ||
val cases1 = typedCases(tree.cases, defn.ThrowableType, pt.notApplied) | ||
val finalizer1 = typed(tree.finalizer, defn.UnitType) | ||
val expr2 :: cases2x = harmonize(expr1 :: cases1) | ||
val cases2 = cases2x.asInstanceOf[List[CaseDef]] | ||
|
@@ -1535,8 +1536,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |
} | ||
|
||
/** If this tree is a select node `qual.name`, try to insert an implicit conversion | ||
* `c` around `qual` so that `c(qual).name` conforms to `pt`. If that fails | ||
* return `tree` itself. | ||
* `c` around `qual` so that `c(qual).name` conforms to `pt`. | ||
*/ | ||
def tryInsertImplicitOnQualifier(tree: Tree, pt: Type)(implicit ctx: Context): Option[Tree] = ctx.traceIndented(i"try insert impl on qualifier $tree $pt") { | ||
tree match { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
object Test { | ||
|
||
val cond = true | ||
def foo1() = println("hi") | ||
def bar1() = println("there") | ||
|
||
def foo2(x: Int) = println("hi") | ||
def bar2(x: Int) = println("there") | ||
|
||
def main(args: Array[String]) = { | ||
(if (cond) foo1 else bar1)() // error: Unit does not take parameters | ||
(if (cond) foo2 else bar2)(22) // error: missing arguments // error: missing arguments | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
hello | ||
hi | ||
33 | ||
hi | ||
hi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
object Test { | ||
|
||
def test1() = | ||
(new Function0[Unit] { | ||
def apply() = println("hello") | ||
})() | ||
|
||
val cond = true | ||
val foo = () => println("hi") | ||
val bar = () => println("there") | ||
|
||
val baz = (x: Int) => println(x) | ||
|
||
def test2() = | ||
(if (cond) foo else bar)() | ||
|
||
def test2a() = | ||
(if (cond) baz else baz)(33) | ||
|
||
def test3() = | ||
(try foo | ||
catch { case ex: Exception => bar } | ||
finally ())() | ||
|
||
def test4() = | ||
(cond match { | ||
case true => foo | ||
case false => bar | ||
})() | ||
|
||
def main(args: Array[String]) = { | ||
test1() | ||
test2() | ||
test2a() | ||
test3() | ||
test4() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: weird indent doesn't match next row