diff options
author | Martin Odersky <odersky@gmail.com> | 2014-11-26 11:46:46 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-11-26 11:46:52 +0100 |
commit | fc319b002ff4bc82061250352f1568c612c70d72 (patch) | |
tree | f2f8a76eb5e8dd8926a35271118cf0e3b91182f5 /tests/pos/refinedSubtyping.scala | |
parent | 5733684a4ec6857ece1048d56654dcd749163510 (diff) | |
download | dotty-fc319b002ff4bc82061250352f1568c612c70d72.tar.gz dotty-fc319b002ff4bc82061250352f1568c612c70d72.tar.bz2 dotty-fc319b002ff4bc82061250352f1568c612c70d72.zip |
Allow refinements that refine already refined types.
Previously, a double definition errorfor `T` was produced in a case like this:
type T1 = C { T <: A }
type T2 = T1 { T <: B }
This was caused by the way T1 was treated in the refinement class
that is used to typecheck the type. Desugaring of T2 with `refinedTypeToClass`
would give
trait <refinement> extends T1 { type T <: B }
and `normalizeToClassRefs` would transform this to:
trait <refinement> extends C { type T <: A; type T <: B }
Hence the double definition. The new scheme desugars the rhs of `T2` to:
trait <refinement> extends C { this: T1 => type T <: B }
which avoids the problem.
Also, added tests that #232 (fix/boundsPropagation) indeed considers all refinements
together when comparing refined types.
Diffstat (limited to 'tests/pos/refinedSubtyping.scala')
-rw-r--r-- | tests/pos/refinedSubtyping.scala | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/pos/refinedSubtyping.scala b/tests/pos/refinedSubtyping.scala index e97d2a264..a01be181d 100644 --- a/tests/pos/refinedSubtyping.scala +++ b/tests/pos/refinedSubtyping.scala @@ -17,3 +17,46 @@ class Test { y = x } + +class Test2 { + + trait A + trait B + + class C { type T } + + type T1 = C { type T <: A } { type T <: B } + + type U1 = C { type T <: B } { type T <: A } + + var x: T1 = _ + var y: U1 = _ + + x = y + y = x +} + + +class Test3 { + + trait A + trait B + + class C { type T } + + type T1 = C { type T <: A } + type T2 = T1 { type T <: B } + + type U1 = C { type T <: B } + type U2 = U1 { type T <: A } + + var x: T2 = _ + var y: U2 = _ + + val x1 = x + val y1 = y + + x = y + y = x + +} |