Skip to content

Commit b3a1626

Browse files
committed
Merge pull request #927 from dotty-staging/stdlib-bounds
Drop checking that lower bound is a subtype of upper bound.
2 parents 3d5a2e2 + 9767782 commit b3a1626

File tree

10 files changed

+31
-14
lines changed

10 files changed

+31
-14
lines changed

src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
415415
// println(owner.info.decls.toList.map(_.debugString).mkString("\n ")) // !!! DEBUG
416416
// }
417417
// (5) Create a stub symbol to defer hard failure a little longer.
418+
println(i"***** missing reference, looking for $name in $owner")
419+
println(i"decls = ${owner.info.decls}")
418420
new Exception().printStackTrace()
419421
ctx.newStubSymbol(owner, name, source)
420422
}

src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
6868
// TODO fill in
6969
}
7070

71-
/** Check bounds of AppliedTypeTrees.
71+
/** Check bounds of AppliedTypeTrees and TypeApplys.
7272
* Replace type trees with TypeTree nodes.
7373
* Replace constant expressions with Literal nodes.
7474
* Note: Demanding idempotency instead of purity in literalize is strictly speaking too loose.
@@ -114,6 +114,9 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
114114
tparam.info.asSeenFrom(tycon.tpe.normalizedPrefix, tparam.owner.owner).bounds)
115115
Checking.checkBounds(args, bounds, _.substDealias(tparams, _))
116116
norm(tree)
117+
case TypeApply(fn, args) =>
118+
Checking.checkBounds(args, fn.tpe.widen.asInstanceOf[PolyType])
119+
norm(tree)
117120
case _ =>
118121
norm(tree)
119122
}

src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ trait Applications extends Compatibility { self: Typer =>
607607
case pt: PolyType =>
608608
if (typedArgs.length <= pt.paramBounds.length)
609609
typedArgs = typedArgs.zipWithConserve(pt.paramBounds)(adaptTypeArg)
610-
checkBounds(typedArgs, pt)
610+
Checking.checkBounds(typedArgs, pt)
611611
case _ =>
612612
}
613613
assignType(cpy.TypeApply(tree)(typedFn, typedArgs), typedFn, typedArgs)

src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ object Checking {
4141
d"Type argument ${arg.tpe} does not conform to $which bound $bound ${err.whyNoMatchStr(arg.tpe, bound)}",
4242
arg.pos)
4343

44+
/** Check that type arguments `args` conform to corresponding bounds in `poly`
45+
* Note: This does not check the bounds of AppliedTypeTrees. These
46+
* are handled by method checkBounds in FirstTransform
47+
*/
48+
def checkBounds(args: List[tpd.Tree], poly: PolyType)(implicit ctx: Context): Unit =
49+
checkBounds(args, poly.paramBounds, _.substParams(poly, _))
50+
4451
/** Check that `tp` refers to a nonAbstract class
4552
* and that the instance conforms to the self type of the created class.
4653
*/
@@ -295,13 +302,6 @@ trait Checking {
295302
tree
296303
}
297304

298-
/** Check that type arguments `args` conform to corresponding bounds in `poly`
299-
* Note: This does not check the bounds of AppliedTypeTrees. These
300-
* are handled by method checkBounds in FirstTransform
301-
*/
302-
def checkBounds(args: List[tpd.Tree], poly: PolyType)(implicit ctx: Context): Unit =
303-
Checking.checkBounds(args, poly.paramBounds, _.substParams(poly, _))
304-
305305
/** Check that type `tp` is stable. */
306306
def checkStable(tp: Type, pos: Position)(implicit ctx: Context): Unit =
307307
if (!tp.isStable && !tp.isErroneous)
@@ -407,7 +407,6 @@ trait NoChecking extends Checking {
407407
import tpd._
408408
override def checkNonCyclic(sym: Symbol, info: TypeBounds, reportErrors: Boolean)(implicit ctx: Context): Type = info
409409
override def checkValue(tree: Tree, proto: Type)(implicit ctx: Context): tree.type = tree
410-
override def checkBounds(args: List[tpd.Tree], poly: PolyType)(implicit ctx: Context): Unit = ()
411410
override def checkStable(tp: Type, pos: Position)(implicit ctx: Context): Unit = ()
412411
override def checkClassTypeWithStablePrefix(tp: Type, pos: Position, traitReq: Boolean)(implicit ctx: Context): Type = tp
413412
override def checkImplicitParamsNotSingletons(vparamss: List[List[ValDef]])(implicit ctx: Context): Unit = ()

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,6 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
866866
val TypeBoundsTree(lo, hi) = desugar.typeBoundsTree(tree)
867867
val lo1 = typed(lo)
868868
val hi1 = typed(hi)
869-
if (!(lo1.tpe <:< hi1.tpe))
870-
ctx.error(d"lower bound ${lo1.tpe} does not conform to upper bound ${hi1.tpe}", tree.pos)
871869
assignType(cpy.TypeBoundsTree(tree)(lo1, hi1), lo1, hi1)
872870
}
873871

test/dotc/scala-collections.whitelist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@
110110
./scala-scala/src/library/scala/collection/immutable/Iterable.scala
111111
./scala-scala/src/library/scala/collection/immutable/LinearSeq.scala
112112

113-
# https://github.com/lampepfl/dotty/issues/915
114-
# ./scala-scala/src/library/scala/collection/immutable/List.scala
113+
./scala-scala/src/library/scala/collection/immutable/List.scala
115114
./scala-scala/src/library/scala/collection/immutable/MapProxy.scala
116115
./scala-scala/src/library/scala/collection/immutable/PagedSeq.scala
117116
./scala-scala/src/library/scala/collection/immutable/Queue.scala

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class tests extends CompilerTest {
108108

109109
@Test def neg_abstractOverride() = compileFile(negDir, "abstract-override", xerrors = 2)
110110
@Test def neg_blockescapes() = compileFile(negDir, "blockescapesNeg", xerrors = 1)
111+
@Test def neg_bounds() = compileFile(negDir, "bounds", xerrors = 2)
111112
@Test def neg_typedapply() = compileFile(negDir, "typedapply", xerrors = 4)
112113
@Test def neg_typedIdents() = compileDir(negDir, "typedIdents", xerrors = 2)
113114
@Test def neg_assignments() = compileFile(negDir, "assignments", xerrors = 3)

tests/neg/bounds.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
class C[B >: String <: Int](x: B)
3+
def g[B >: String <: Int](x: B): Int = x
4+
def main(args: Array[String]): Unit = {
5+
g("foo")
6+
new C("bar")
7+
}
8+
}

tests/pos/bounds.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ object ListMap {
99
def empty[X, Y] = new ListMap[X, Y]
1010
def apply[A1, B2](elems: Tuple2[A1, B2]*): Map[A1, B2] = empty[A1,B2].++(elems.iterator)
1111
}
12+
13+
class Test[A] {
14+
15+
def f[B >: A <: AnyRef](x: A): AnyRef = (x: B)
16+
def g[B >: String <: Int](x: B): Int = x
17+
18+
}
File renamed without changes.

0 commit comments

Comments
 (0)