Skip to content

Fix #6247: Remove incorrect early check #6301

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
Apr 15, 2019
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
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,14 @@ trait Inferencing { this: Typer =>
*/
def interpolateTypeVars(tree: Tree, pt: Type, locked: TypeVars)(implicit ctx: Context): tree.type = {
val state = ctx.typerState
if (state.ownedVars.size > locked.size) {
val qualifying = state.ownedVars -- locked

// Note that some variables in `locked` might not be in `state.ownedVars`
// anymore if they've been garbage-collected, so we can't use
// `state.ownedVars.size > locked.size` as an early check to avoid computing
// `qualifying`.
val qualifying = state.ownedVars -- locked

if (!qualifying.isEmpty) {
typr.println(i"interpolate $tree: ${tree.tpe.widen} in $state, owned vars = ${state.ownedVars.toList}%, %, previous = ${locked.toList}%, % / ${state.constraint}")
val resultAlreadyConstrained =
tree.isInstanceOf[Apply] || tree.tpe.isInstanceOf[MethodOrPoly]
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/util/SimpleIdentitySet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import collection.mutable.ListBuffer
*/
abstract class SimpleIdentitySet[+Elem <: AnyRef] {
def size: Int
def isEmpty: Boolean = size == 0
def + [E >: Elem <: AnyRef](x: E): SimpleIdentitySet[E]
def - [E >: Elem <: AnyRef](x: E): SimpleIdentitySet[Elem]
def contains[E >: Elem <: AnyRef](x: E): Boolean
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i6247.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Foo {
implicit class NN[T](x:T|Null) {
def nn: T = x.asInstanceOf[T]
}

val x1: String|Null = null
x1.nn.length
val x2: String = x1.nn
x1.nn.length
}