Skip to content

Commit aaa32f7

Browse files
authored
Merge pull request #1455 from dotty-staging/tests2
Fix remaining hk issues in pending
2 parents 83adc75 + 0faeeba commit aaa32f7

19 files changed

+40
-30
lines changed

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
580580
*/
581581
def compareHkApply2(tp1: Type, tp2: HKApply, tycon2: Type, args2: List[Type]): Boolean = {
582582
val tparams = tycon2.typeParams
583-
assert(tparams.nonEmpty)
583+
if (tparams.isEmpty) return false // can happen for ill-typed programs, e.g. neg/tcpoly_overloaded.scala
584584

585585
/** True if `tp1` and `tp2` have compatible type constructors and their
586586
* corresponding arguments are subtypes relative to their variance (see `isSubArgs`).

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ object EtaExpansion {
142142
var ids: List[Tree] = mt.paramNames map (name => Ident(name).withPos(tree.pos))
143143
if (mt.paramTypes.nonEmpty && mt.paramTypes.last.isRepeatedParam)
144144
ids = ids.init :+ repeated(ids.last)
145-
val body = Apply(lifted, ids)
145+
var body: Tree = Apply(lifted, ids)
146+
mt.resultType match {
147+
case rt: MethodType if !rt.isImplicit => body = PostfixOp(body, nme.WILDCARD)
148+
case _ =>
149+
}
146150
val fn = untpd.Function(params, body)
147151
if (defs.nonEmpty) untpd.Block(defs.toList map untpd.TypedSplice, fn) else fn
148152
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ trait TypeAssigner {
9494
case _ =>
9595
mapOver(tp)
9696
}
97+
case tp @ HKApply(tycon, args) if toAvoid(tycon) =>
98+
apply(tp.superType)
9799
case tp @ AppliedType(tycon, args) if toAvoid(tycon) =>
98100
val base = apply(tycon)
99101
var args = tp.baseArgInfos(base.typeSymbol)
100102
if (base.typeParams.length != args.length)
101103
args = base.typeParams.map(_.paramBounds)
102-
base.appliedTo(args)
104+
apply(base.appliedTo(args))
103105
case tp @ RefinedType(parent, name, rinfo) if variance > 0 =>
104106
val parent1 = apply(tp.parent)
105107
val refinedInfo1 = apply(rinfo)

tests/neg/tcpoly_overloaded.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
trait Monad[T <: Bound[T], MyType[x <: Bound[x]], Bound[_]] {
2+
def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_],
3+
Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]]
4+
(f: T => Result[S]): Result[S]
5+
def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_],
6+
Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]]
7+
(f: T => Result[S], foo: String): Result[S]
8+
def flatMap[S <: Bound[S]]
9+
(f: T => MyType[S], foo: Int): MyType[S]
10+
}
11+
12+
trait Test {
13+
def moo: MList[Int]
14+
class MList[T](el: T) extends Monad[T, List, Any] { // error: does not conform to upper bound // error
15+
def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_],
16+
Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]]
17+
(f: T => Result[S]): Result[S] = sys.error("foo")
18+
def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_],
19+
Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]]
20+
(f: T => Result[S], foo: String): Result[S] = sys.error("foo")
21+
def flatMap[S]
22+
(f: T => List[S], foo: Int): List[S] = sys.error("foo")
23+
}
24+
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String")) // error: does not conform to upper bound // error
25+
}

tests/pending/run/tcpoly_parseridioms.check

Lines changed: 0 additions & 21 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

tests/pending/pos/spec-traits.scala renamed to tests/pos/spec-traits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class Bug3307 {
2525
class Bug3301 {
2626
def t[A]: T[A] = sys.error("stub")
2727

28-
() => {
28+
{() => {
2929
type X = Int
3030

3131
def foo[X] = t[X]
3232
()
33-
}
33+
}}
3434
}
3535
// issue 3299
3636
object Failure {

tests/pending/pos/tcpoly_bounds1.scala renamed to tests/pos/tcpoly_bounds1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object foo extends Foo[MyPair]
77

88

99
trait Monad[m[x <: Bound[x]], Bound[x], a] // TODO: variances!
10-
trait ListMonad[a] extends Monad[List, Any, a]
10+
trait ListMonad[a] extends Monad[List, [X] -> Any, a] // Dotty difference: Any is not a legal argument for hk type.
1111

1212
trait MyOrdered[a]
1313
trait MySet[x <: MyOrdered[x]]

tests/pending/pos/tcpoly_overloaded.scala renamed to tests/pos/tcpoly_overloaded.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait Monad[T <: Bound[T], MyType[x <: Bound[x]], Bound[_]] {
1111

1212
trait Test {
1313
def moo: MList[Int]
14-
class MList[T](el: T) extends Monad[T, List, Any] {
14+
class MList[T](el: T) extends Monad[T, List, [X] -> Any] {
1515
def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_],
1616
Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]]
1717
(f: T => Result[S]): Result[S] = sys.error("foo")
@@ -21,5 +21,5 @@ trait Test {
2121
def flatMap[S]
2222
(f: T => List[S], foo: Int): List[S] = sys.error("foo")
2323
}
24-
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String"))
24+
val l: MList[String] = moo.flatMap[String, List, [X] -> Any, MList]((x: Int) => new MList("String"))
2525
}
File renamed without changes.

tests/pending/run/tcpoly_parseridioms.scala renamed to tests/run/tcpoly_parseridioms.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ trait ParserIdioms extends Parsers with Idioms {
108108
}
109109

110110
object Test extends ParserIdioms with App {
111-
println(expr("12".toList))
111+
assert(expr("12".toList).toString == "Success(List(),Plus(1,2))")
112112
}

0 commit comments

Comments
 (0)