diff options
author | Martin Odersky <odersky@gmail.com> | 2017-03-19 12:44:27 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2017-04-06 13:15:29 +0200 |
commit | 8d33ca7460493427055daaecca53c66127772831 (patch) | |
tree | 2c8f539d138a1374dde36c58ffb2f1d4c0841dfa /compiler/src/dotty/tools/dotc/typer | |
parent | 15317555c94f613f266d7b0fb0a75b0b6ed2da6d (diff) | |
download | dotty-8d33ca7460493427055daaecca53c66127772831.tar.gz dotty-8d33ca7460493427055daaecca53c66127772831.tar.bz2 dotty-8d33ca7460493427055daaecca53c66127772831.zip |
Merge MethodType and PolyType functionality where possible
Two benefits: (1) less code. (2) finding subtle bugs about
parameter dependent method types. By merging with PolyTypes
we are forced to take parameter dependencies into account.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer')
5 files changed, 7 insertions, 15 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 25c9c13d8..4e43e429b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1284,8 +1284,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => case x => x } - def sizeFits(alt: TermRef, tp: Type): Boolean = tp match { - case tp: PolyType => sizeFits(alt, tp.resultType) + def sizeFits(alt: TermRef, tp: Type): Boolean = tp.stripPoly match { case tp: MethodType => val ptypes = tp.paramInfos val numParams = ptypes.length diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 703d2fc3c..6c0be51df 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -107,9 +107,8 @@ object Implicits { !(isFunctionInS2 || isImplicitConverter || isConforms) } - def discardForValueType(tpw: Type): Boolean = tpw match { + def discardForValueType(tpw: Type): Boolean = tpw.stripPoly match { case tpw: MethodType => !tpw.isImplicit - case tpw: PolyType => discardForValueType(tpw.resultType) case _ => false } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 9a9e45941..723e7007f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -748,7 +748,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case _ => } val ofFun = - if (nme.syntheticParamNames(args.length + 1) contains param.name) + if (MethodType.syntheticParamNames(args.length + 1) contains param.name) i" of expanded function $tree" else "" @@ -1285,9 +1285,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit * @param psym Its type symbol * @param cinfo The info of its constructor */ - def maybeCall(ref: Tree, psym: Symbol, cinfo: Type): Tree = cinfo match { - case cinfo: PolyType => - maybeCall(ref, psym, cinfo.resultType) + def maybeCall(ref: Tree, psym: Symbol, cinfo: Type): Tree = cinfo.stripPoly match { case cinfo @ MethodType(Nil) if cinfo.resultType.isInstanceOf[ImplicitMethodType] => val icall = New(ref).select(nme.CONSTRUCTOR).appliedToNone typedExpr(untpd.TypedSplice(icall))(superCtx) diff --git a/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala b/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala index d5dd5a024..f88098519 100644 --- a/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala +++ b/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala @@ -88,10 +88,8 @@ class VarianceChecker()(implicit ctx: Context) { if (sym.variance != 0 && base.isContainedIn(sym.owner)) checkVarianceOfSymbol(sym) else if (sym.isAliasType) this(status, sym.info.bounds.hi) else foldOver(status, tp) - case tp: MethodType => - this(status, tp.resultType) // params will be checked in their TypeDef nodes. - case tp: PolyType => - this(status, tp.resultType) // params will be checked in their ValDef nodes. + case tp: MethodOrPoly => + this(status, tp.resultType) // params will be checked in their TypeDef or ValDef nodes. case AnnotatedType(_, annot) if annot.symbol == defn.UncheckedVarianceAnnot => status //case tp: ClassInfo => diff --git a/compiler/src/dotty/tools/dotc/typer/Variances.scala b/compiler/src/dotty/tools/dotc/typer/Variances.scala index 83ac23f7e..aeeef0275 100644 --- a/compiler/src/dotty/tools/dotc/typer/Variances.scala +++ b/compiler/src/dotty/tools/dotc/typer/Variances.scala @@ -79,7 +79,7 @@ object Variances { varianceInType(parent)(tparam) & varianceInType(rinfo)(tparam) case tp: RecType => varianceInType(tp.parent)(tparam) - case tp: MethodType => + case tp: MethodOrPoly => flip(varianceInTypes(tp.paramInfos)(tparam)) & varianceInType(tp.resultType)(tparam) case ExprType(restpe) => varianceInType(restpe)(tparam) @@ -94,8 +94,6 @@ object Variances { v } varianceInArgs(varianceInType(tycon)(tparam), args, tycon.typeParams) - case tp: PolyType => - flip(varianceInTypes(tp.paramInfos)(tparam)) & varianceInType(tp.resultType)(tparam) case AnnotatedType(tp, annot) => varianceInType(tp)(tparam) & varianceInAnnot(annot)(tparam) case tp: AndOrType => |