Skip to content

Match Types: implement cantPossiblyMatch #5996

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 20 commits into from
Mar 9, 2019
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c1b7e84
Minor TypeTestsCasts refactoring
OlivierBlanvillain Feb 11, 2019
6e39fcb
Rename evalOnce to letBind
OlivierBlanvillain Feb 11, 2019
eef623a
Rename cmp to typeComparer
OlivierBlanvillain Feb 11, 2019
6755f52
Remove reduceParallel
OlivierBlanvillain Feb 18, 2019
88cfb7e
Fix spacing for TypeComparer comments
OlivierBlanvillain Feb 21, 2019
bb1515e
Flag ChildrenQueried in hasAnonymousChild
OlivierBlanvillain Feb 22, 2019
f79d937
Implement cantPossiblyMatch
OlivierBlanvillain Mar 1, 2019
60d0e20
Replace Space.inhabited by typeComparer.intersecting
OlivierBlanvillain Feb 28, 2019
d1180cc
Move refineUsingParent to Typer
OlivierBlanvillain Feb 26, 2019
b0c1e7b
Check inhabitation of children in Space
OlivierBlanvillain Feb 28, 2019
c3d23fe
Only trust isSameType for fully instanciated types
OlivierBlanvillain Feb 28, 2019
4f934ad
Use derivesFrom instead of isSubType for classes
OlivierBlanvillain Mar 1, 2019
80c25e3
Handle type parameters using symbol.is(TypeParam)
OlivierBlanvillain Mar 4, 2019
ab74827
Fix AppliedType logic
OlivierBlanvillain Mar 4, 2019
1df0d8b
Revert "Rename evalOnce to letBind"
OlivierBlanvillain Mar 6, 2019
8827eff
Revert "Flag ChildrenQueried in hasAnonymousChild"
OlivierBlanvillain Mar 6, 2019
ffa8acf
Address review
OlivierBlanvillain Mar 6, 2019
e7f6049
Move refineUsingParent to TypeOps
OlivierBlanvillain Mar 6, 2019
f4df58d
Factor out cov. test and use it in the inv. case
OlivierBlanvillain Mar 6, 2019
ea04343
Update inhabited check in Space
OlivierBlanvillain Mar 6, 2019
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
16 changes: 15 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,21 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
// instantiated to `Any` belongs to both types.
true
else
isSameType(arg1, arg2) // TODO: handle uninstanciated types
isSameType(arg1, arg2) || {
// We can only trust a "no" from `isSameType` when both
// `arg1` and `arg2` are fully instantiated.
val fullyInstantiated = new TypeAccumulator[Boolean] {
override def apply(x: Boolean, t: Type) =
x && {
t match {
case _: SkolemType | _: TypeVar | _: TypeParamRef => false
case _ => foldOver(x, t)
}
}
}
!(fullyInstantiated.apply(true, arg1) &&
fullyInstantiated.apply(true, arg2))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this still misses the case where we have an abstract TypeRef that is not a type parameter. Also, it is a bit unsatisfactory that for toplevel TypeRefs and TypeParamRefs we go to their supertypes but here we do not. So if I understand correctly in the case where we have a TypeParamRef A <: Int and a TypeParamRef B <: String, we would diagnose a possible overlap for

NonVariant[A], NonVariant[B]

but no such overlap for

CoVariant[A], Covariant[B]

(because for the latter we do a recursive call of intersecting).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this still misses the case where we have an abstract TypeRef that is not a type parameter.

I changed the test from tp.symbol.is(TypeParam) to tp.symbol.isAbstractOrParamType and added a test.

Also, it is a bit unsatisfactory that for toplevel TypeRefs and TypeParamRefs we go to their supertypes but here we do not. [...]

Indeed, I guess I can also run the covariant test in the invariant case, invariance should give us more ways to prove non overlap, not less!

}
}
case (tp1: HKLambda, tp2: HKLambda) =>
intersecting(tp1.resType, tp2.resType)
Expand Down