Skip to content

Fix remaining hk issues in pending #1455

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 4 commits into from
Aug 18, 2016
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
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
*/
def compareHkApply2(tp1: Type, tp2: HKApply, tycon2: Type, args2: List[Type]): Boolean = {
val tparams = tycon2.typeParams
assert(tparams.nonEmpty)
if (tparams.isEmpty) return false // can happen for ill-typed programs, e.g. neg/tcpoly_overloaded.scala

/** True if `tp1` and `tp2` have compatible type constructors and their
* corresponding arguments are subtypes relative to their variance (see `isSubArgs`).
Expand Down
6 changes: 5 additions & 1 deletion src/dotty/tools/dotc/typer/EtaExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ object EtaExpansion {
var ids: List[Tree] = mt.paramNames map (name => Ident(name).withPos(tree.pos))
if (mt.paramTypes.nonEmpty && mt.paramTypes.last.isRepeatedParam)
ids = ids.init :+ repeated(ids.last)
val body = Apply(lifted, ids)
var body: Tree = Apply(lifted, ids)
mt.resultType match {
case rt: MethodType if !rt.isImplicit => body = PostfixOp(body, nme.WILDCARD)
case _ =>
}
val fn = untpd.Function(params, body)
if (defs.nonEmpty) untpd.Block(defs.toList map untpd.TypedSplice, fn) else fn
}
Expand Down
4 changes: 3 additions & 1 deletion src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ trait TypeAssigner {
case _ =>
mapOver(tp)
}
case tp @ HKApply(tycon, args) if toAvoid(tycon) =>
apply(tp.superType)
case tp @ AppliedType(tycon, args) if toAvoid(tycon) =>
val base = apply(tycon)
var args = tp.baseArgInfos(base.typeSymbol)
if (base.typeParams.length != args.length)
args = base.typeParams.map(_.paramBounds)
base.appliedTo(args)
apply(base.appliedTo(args))
case tp @ RefinedType(parent, name, rinfo) if variance > 0 =>
val parent1 = apply(tp.parent)
val refinedInfo1 = apply(rinfo)
Expand Down
25 changes: 25 additions & 0 deletions tests/neg/tcpoly_overloaded.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
trait Monad[T <: Bound[T], MyType[x <: Bound[x]], Bound[_]] {
def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_],
Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]]
(f: T => Result[S]): Result[S]
def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_],
Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]]
(f: T => Result[S], foo: String): Result[S]
def flatMap[S <: Bound[S]]
(f: T => MyType[S], foo: Int): MyType[S]
}

trait Test {
def moo: MList[Int]
class MList[T](el: T) extends Monad[T, List, Any] { // error: does not conform to upper bound // error
def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_],
Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]]
(f: T => Result[S]): Result[S] = sys.error("foo")
def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_],
Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]]
(f: T => Result[S], foo: String): Result[S] = sys.error("foo")
def flatMap[S]
(f: T => List[S], foo: Int): List[S] = sys.error("foo")
}
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String")) // error: does not conform to upper bound // error
}
21 changes: 0 additions & 21 deletions tests/pending/run/tcpoly_parseridioms.check

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class Bug3307 {
class Bug3301 {
def t[A]: T[A] = sys.error("stub")

() => {
{() => {
type X = Int

def foo[X] = t[X]
()
}
}}
}
// issue 3299
object Failure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object foo extends Foo[MyPair]


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

trait MyOrdered[a]
trait MySet[x <: MyOrdered[x]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait Monad[T <: Bound[T], MyType[x <: Bound[x]], Bound[_]] {

trait Test {
def moo: MList[Int]
class MList[T](el: T) extends Monad[T, List, Any] {
class MList[T](el: T) extends Monad[T, List, [X] -> Any] {
def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_],
Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]]
(f: T => Result[S]): Result[S] = sys.error("foo")
Expand All @@ -21,5 +21,5 @@ trait Test {
def flatMap[S]
(f: T => List[S], foo: Int): List[S] = sys.error("foo")
}
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String"))
val l: MList[String] = moo.flatMap[String, List, [X] -> Any, MList]((x: Int) => new MList("String"))
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ trait ParserIdioms extends Parsers with Idioms {
}

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