Skip to content

Fix/#290 type bind #292

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 2 commits into from
Dec 16, 2014
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: 2 additions & 0 deletions src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ object Trees {
case class Bind[-T >: Untyped] private[ast] (name: Name, body: Tree[T])
extends NameTree[T] with DefTree[T] with PatternTree[T] {
type ThisTree[-T >: Untyped] = Bind[T]
override def isType = name.isTypeName
override def isTerm = name.isTermName
override def envelope: Position = pos union initialPos
}

Expand Down
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ trait TypeAssigner {
def assignType(tree: untpd.TypeBoundsTree, lo: Tree, hi: Tree)(implicit ctx: Context) =
tree.withType(TypeBounds(lo.tpe, hi.tpe))

def assignType(tree: untpd.Bind, sym: TermSymbol)(implicit ctx: Context) =
tree.withType(TermRef(NoPrefix, sym))
def assignType(tree: untpd.Bind, sym: Symbol)(implicit ctx: Context) =
tree.withType(NamedType.withFixedSym(NoPrefix, sym))

def assignType(tree: untpd.Alternative, trees: List[Tree])(implicit ctx: Context) =
tree.withType(ctx.typeComparer.lub(trees.tpes))
Expand Down
9 changes: 6 additions & 3 deletions src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit

def typedAppliedTypeTree(tree: untpd.AppliedTypeTree)(implicit ctx: Context): AppliedTypeTree = track("typedAppliedTypeTree") {
val tpt1 = typed(tree.tpt)
val args1 = tree.args mapconserve (typed(_))
val argPts =
if (ctx.mode is Mode.Pattern) tpt1.tpe.typeParams.map(_.info)
else tree.args.map(_ => WildcardType)
val args1 = tree.args.zipWithConserve(argPts)(typed(_, _)).asInstanceOf[List[Tree]]
// check that arguments conform to bounds is done in phase FirstTransform
assignType(cpy.AppliedTypeTree(tree)(tpt1, args1), tpt1, args1)
}
Expand All @@ -798,7 +801,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
def typedBind(tree: untpd.Bind, pt: Type)(implicit ctx: Context): Bind = track("typedBind") {
val body1 = typed(tree.body, pt)
typr.println(i"typed bind $tree pt = $pt bodytpe = ${body1.tpe}")
val sym = ctx.newSymbol(ctx.owner, tree.name.asTermName, EmptyFlags, body1.tpe, coord = tree.pos)
val sym = ctx.newSymbol(ctx.owner, tree.name, EmptyFlags, body1.tpe, coord = tree.pos)
assignType(cpy.Bind(tree)(tree.name, body1), sym)
}

Expand Down Expand Up @@ -1339,7 +1342,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
}
case _ =>
if (ctx.mode is Mode.Type)
if (tree.tpe <:< pt) tree
if ((ctx.mode is Mode.Pattern) || tree.tpe <:< pt) tree
else err.typeMismatch(tree, pt)
else adaptNoArgs(wtp)
}
Expand Down
19 changes: 19 additions & 0 deletions tests/pos/i0290-type-bind.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
object foo{
val x = List(1,2,3)
x match {
case t: List[tt] => t.head.asInstanceOf[tt]
}
}

object bar {

class C[T <: Seq[_]]

val x: AnyRef = new C

x match {
case x: C[u] =>
def x: u = x
val s: Seq[_] = x
}
}