aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-12-15 12:26:04 +0100
committerMartin Odersky <odersky@gmail.com>2013-12-15 12:26:04 +0100
commit99393624e3bf001a6c20c7615ac88ef4201a93f8 (patch)
tree1f3a8800364fcfb1001b08a335acdfe8fa288c01 /src/dotty/tools/dotc/typer/Typer.scala
parent01db9a68e5e68f08c8236c23c905009789d51587 (diff)
downloaddotty-99393624e3bf001a6c20c7615ac88ef4201a93f8.tar.gz
dotty-99393624e3bf001a6c20c7615ac88ef4201a93f8.tar.bz2
dotty-99393624e3bf001a6c20c7615ac88ef4201a93f8.zip
Fixes related to SAM types.
1. Changes to SAMType extractor 2. Self names are no longer members of enclosing class 3. SAM-Type closures now print with their result type. 4. refactoring newSkolemSingleon ==> narrow
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index b2796f62f..dda50a323 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -506,16 +506,18 @@ class Typer extends Namer with Applications with Implicits {
val untpd.Function(args, body) = tree
if (ctx.mode is Mode.Type)
typed(cpy.AppliedTypeTree(tree,
- ref(defn.FunctionClass(args.length).typeRef), args :+ body), pt)
+ untpd.TypeTree(defn.FunctionClass(args.length).typeRef), args :+ body), pt)
else {
val params = args.asInstanceOf[List[ValDef]]
val protoFormals: List[Type] = pt match {
case _ if pt isRef defn.FunctionClass(params.length) =>
pt.typeArgs take params.length
case SAMType(meth) =>
+ // println(s"SAMType $pt")
val MethodType(_, paramTypes) = meth.info
paramTypes
case _ =>
+ // println(s"Neither fucntion nor SAM type $pt")
params map alwaysWildcardType
}
val inferredParams: List[untpd.ValDef] =
@@ -527,7 +529,7 @@ class Typer extends Namer with Applications with Implicits {
else {
val ofFun =
if (nme.syntheticParamNames(args.length + 1) contains param.name)
- s" for expanded function ${tree.show}"
+ s" of expanded function ${tree.show}"
else ""
errorType(s"missing parameter type for parameter ${param.name}$ofFun, expected = ${pt.show}", param.pos)
}
@@ -540,14 +542,21 @@ class Typer extends Namer with Applications with Implicits {
def typedClosure(tree: untpd.Closure, pt: Type)(implicit ctx: Context) = track("typedClosure") {
val env1 = tree.env mapconserve (typed(_))
val meth1 = typedUnadapted(tree.meth)
- val ownType = meth1.tpe.widen match {
+ val (ownType, target) = meth1.tpe.widen match {
case mt: MethodType =>
- if (!mt.isDependent) mt.toFunctionType
- else throw new Error(s"internal error: cannot turn dependent method type $mt into closure, position = ${tree.pos}") // !!! DEBUG. Eventually, convert to an error?
+ pt match {
+ case SAMType(meth) if !defn.isFunctionType(pt) && mt <:< meth.info =>
+ if (!isFullyDefined(pt, ForceDegree.all))
+ ctx.error(i"result type of closure is an underspecified SAM type $pt", tree.pos)
+ (pt, TypeTree(pt))
+ case _ =>
+ if (!mt.isDependent) (mt.toFunctionType, EmptyTree)
+ else throw new Error(s"internal error: cannot turn dependent method type $mt into closure, position = ${tree.pos}") // !!! DEBUG. Eventually, convert to an error?
+ }
case tp =>
throw new Error(i"internal error: closing over non-method $tp, pos = ${tree.pos}")
}
- cpy.Closure(tree, env1, meth1, EmptyTree).withType(ownType)
+ cpy.Closure(tree, env1, meth1, target).withType(ownType)
}
def typedMatch(tree: untpd.Match, pt: Type)(implicit ctx: Context) = track("typedMatch") {