aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-11-17 12:36:58 +0100
committerMartin Odersky <odersky@gmail.com>2015-11-17 12:37:03 +0100
commite59c0baaff669d54eb502b2142783d9f5d75e3b5 (patch)
tree305d9d44ac4b23e968699d2998d8f2a185e617bf /src/dotty/tools/dotc/typer/Typer.scala
parent6b061b5b94fb4e13a97274b28e0ab9ac78b69f27 (diff)
downloaddotty-e59c0baaff669d54eb502b2142783d9f5d75e3b5.tar.gz
dotty-e59c0baaff669d54eb502b2142783d9f5d75e3b5.tar.bz2
dotty-e59c0baaff669d54eb502b2142783d9f5d75e3b5.zip
More refined treatement of pattern type variables
Previously all lower case names were treated as variables in patterns. But that made code like x: cls crash the compiler if `cls` was a class. Also, it owuld preventing this idiom unless one wrote x: `cls` We now do it like scalac and treat lower case names as variables only in arguments of types.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index d54c9f731..0ae04cbe8 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -253,8 +253,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
if (ctx.mode is Mode.Pattern) {
if (name == nme.WILDCARD)
return tree.withType(pt)
- if (isVarPattern(tree))
- return typed(untpd.Bind(name, untpd.Ident(nme.WILDCARD)).withPos(tree.pos), pt)
+ if (isVarPattern(tree) && name.isTermName)
+ return typed(desugar.patternVar(tree), pt)
}
val saved = importedFromRoot
@@ -848,7 +848,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
args = args.take(tparams.length)
}
def typedArg(arg: untpd.Tree, tparam: Symbol) = {
- val arg1 = typed(arg, if (ctx.mode is Mode.Pattern) tparam.info else WildcardType)
+ val (desugaredArg, argPt) =
+ if (ctx.mode is Mode.Pattern)
+ (if (isVarPattern(arg)) desugar.patternVar(arg) else arg, tparam.info)
+ else
+ (arg, WildcardType)
+ val arg1 = typed(desugaredArg, argPt)
adaptTypeArg(arg1, if (tparam.isCompleted) tparam.info else WildcardType)
}
val args1 = args.zipWithConserve(tparams)(typedArg(_, _)).asInstanceOf[List[Tree]]