Skip to content

Improve variable instantiation when member is missing #11242

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
Jan 29, 2021
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
17 changes: 16 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,23 @@ object Inferencing {
&& tvar.hasLowerBound =>
tvar.instantiate(fromBelow = true)
true
case AppliedType(tycon, _) =>
case AppliedType(tycon, args) =>
// The argument in `args` that may potentially appear directly as result
// and thereby influence the members of this type
def argsInResult: List[Type] = tycon match
case tycon: TypeRef =>
tycon.info match
case MatchAlias(_) => args
case TypeBounds(_, upper: TypeLambda) =>
upper.resultType match
case ref: TypeParamRef if ref.binder == upper =>
args.lazyZip(upper.paramRefs).collect {
case (arg, pref) if pref eq ref => arg
}.toList
case _ => Nil
case _ => Nil
couldInstantiateTypeVar(tycon)
|| argsInResult.exists(couldInstantiateTypeVar)
case RefinedType(parent, _, _) =>
couldInstantiateTypeVar(parent)
case tp: AndOrType =>
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ i7868.scala
i7872.scala
6709.scala
6687.scala
i11236.scala

# Opaque type
i5720.scala
Expand Down
22 changes: 22 additions & 0 deletions tests/pos/i11236.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Test {
val tup: Char #: Int #: String #: TupleK = ???
val x: String #: TupleK = (tup.tail: Int #: String #: TupleK).tail
val a = tup.tail
val b = a.tail
val y: String #: TupleK = tup.tail.tail
val z: Unit = tup.tail.tail
}

trait TupleK

object TupleK {
type Tail[X <: NonEmptyTupleK] <: TupleK = X match {
case _ #: xs => xs
}
}

trait NonEmptyTupleK extends TupleK {
/*inline*/ def tail[This >: this.type <: NonEmptyTupleK]: TupleK.Tail[This] = ???
}

abstract class #:[+H, +T <: TupleK] extends NonEmptyTupleK
12 changes: 7 additions & 5 deletions tests/pos/i9567.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// val x: Int => Int = identity
// }

trait Foo[F[_]] {
trait Foo[F[_], I[X] <: X] {
type Id[X] <: X
def foo[G[x] >: F[x]]: G[Unit]
def foo2[X >: F[String]]: Id[X]
def foo3[X >: F[String]]: I[X]
}

trait M[A] {
Expand All @@ -12,11 +15,10 @@ trait M[A] {
}

object Test {
def bar(x: Foo[M]): Unit = {
// error: value bla is not a member of G[Unit], where: G is a type variable with constraint >: M and <: [x] =>> Any
def bar(x: Foo[M, [X] =>> X]): Unit = {
x.foo.bla

// error: value bla is not a member of G[Unit], where: G is a type variable with constraint >: M and <: [x] =>> Any
x.foo.baz(x => x)
x.foo2.bla
x.foo3.bla
}
}