From db4f7a19c9329d59da09a4de6b8476b4b6988cdf Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 18 Mar 2017 11:26:59 +0100 Subject: Further refactorings - Use TypeLambda instead of PolyType. - Further harmonize factory operations --- compiler/src/dotty/tools/dotc/typer/Applications.scala | 9 ++------- compiler/src/dotty/tools/dotc/typer/Checking.scala | 8 ++++---- compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Implicits.scala | 6 +++--- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Namer.scala | 4 ++-- compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala | 2 +- 7 files changed, 14 insertions(+), 19 deletions(-) (limited to 'compiler/src/dotty/tools/dotc/typer') diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index cd7c7fd66..25c9c13d8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -34,7 +34,7 @@ object Applications { def extractorMember(tp: Type, name: Name)(implicit ctx: Context) = { def isPossibleExtractorType(tp: Type) = tp match { - case _: MethodType | _: PolyType => false + case _: MethodOrPoly => false case _ => true } tp.member(name).suchThat(d => isPossibleExtractorType(d.info)) @@ -1412,12 +1412,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => recur(altFormals.map(_.tail), args1) case _ => } - def paramTypes(alt: Type): List[Type] = alt match { - case mt: MethodType => mt.paramInfos - case mt: PolyType => paramTypes(mt.resultType) - case _ => Nil - } - recur(alts.map(alt => paramTypes(alt.widen)), pt.args) + recur(alts.map(_.widen.firstParamTypes), pt.args) } private def harmonizeWith[T <: AnyRef](ts: List[T])(tpe: T => Type, adapt: (T, Type) => T)(implicit ctx: Context): List[T] = { diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index e959e6984..00d36651e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -50,12 +50,12 @@ object Checking { arg.pos.focus) } - /** Check that type arguments `args` conform to corresponding bounds in `poly` + /** Check that type arguments `args` conform to corresponding bounds in `tl` * Note: This does not check the bounds of AppliedTypeTrees. These * are handled by method checkBounds in FirstTransform */ - def checkBounds(args: List[tpd.Tree], poly: PolyType)(implicit ctx: Context): Unit = - checkBounds(args, poly.paramInfos, _.substParams(poly, _)) + def checkBounds(args: List[tpd.Tree], tl: TypeLambda)(implicit ctx: Context): Unit = + checkBounds(args, tl.paramInfos, _.substParams(tl, _)) /** Check applied type trees for well-formedness. This means * - all arguments are within their corresponding bounds @@ -82,7 +82,7 @@ object Checking { def checkWildcardHKApply(tp: Type, pos: Position): Unit = tp match { case tp @ HKApply(tycon, args) if args.exists(_.isInstanceOf[TypeBounds]) => tycon match { - case tycon: PolyType => + case tycon: TypeLambda => ctx.errorOrMigrationWarning( ex"unreducible application of higher-kinded type $tycon to wildcard arguments", pos) diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala index 5063a111c..6c72c16e0 100644 --- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -74,7 +74,7 @@ object ErrorReporting { def anonymousTypeMemberStr(tpe: Type) = { val kind = tpe match { case _: TypeBounds => "type with bounds" - case _: PolyType | _: MethodType => "method" + case _: MethodOrPoly => "method" case _ => "value of type" } em"$kind $tpe" diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index af2145376..703d2fc3c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -108,8 +108,8 @@ object Implicits { } def discardForValueType(tpw: Type): Boolean = tpw match { - case mt: MethodType => !mt.isImplicit - case mt: PolyType => discardForValueType(tpw.resultType) + case tpw: MethodType => !tpw.isImplicit + case tpw: PolyType => discardForValueType(tpw.resultType) case _ => false } @@ -387,7 +387,7 @@ trait ImplicitRunInfo { self: RunInfo => case _ => arg } (apply(tp.tycon) /: tp.args)((tc, arg) => AndType.make(tc, applyArg(arg))) - case tp: PolyType => + case tp: TypeLambda => apply(tp.resType) case _ => mapOver(tp) diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 6ef6c12cc..90052a1ed 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -120,7 +120,7 @@ object Inliner { // Abstract accessed type over local refs def abstractQualType(mtpe: Type): Type = if (localRefs.isEmpty) mtpe - else mtpe.LambdaAbstract(localRefs.map(_.symbol)).asInstanceOf[PolyType].flatten + else PolyType.fromParams(localRefs.map(_.symbol.asType), mtpe).flatten val accessorType = abstractQualType(addQualType(dealiasMap(accessedType))) val accessor = accessorSymbol(tree, accessorType).asTerm diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 54e9af593..bdf044aa8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -113,9 +113,9 @@ trait NamerContextOps { this: Context => if (isJava) for (param <- params) if (param.info.isDirectRef(defn.ObjectClass)) param.info = defn.AnyType - make.fromSymbols(params, resultType) + make.fromSymbols(params.asInstanceOf[List[TermSymbol]], resultType) } - if (typeParams.nonEmpty) monotpe.LambdaAbstract(typeParams) + if (typeParams.nonEmpty) monotpe.LambdaAbstract(typeParams.asInstanceOf[List[TypeSymbol]]) else if (valueParamss.isEmpty) ExprType(monotpe) else monotpe } diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 0edb22b06..4416428f4 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -460,7 +460,7 @@ trait TypeAssigner { } def assignType(tree: untpd.LambdaTypeTree, tparamDefs: List[TypeDef], body: Tree)(implicit ctx: Context) = - tree.withType(body.tpe.LambdaAbstract(tparamDefs.map(_.symbol))) + tree.withType(body.tpe.LambdaAbstract(tparamDefs.map(_.symbol.asType))) def assignType(tree: untpd.ByNameTypeTree, result: Tree)(implicit ctx: Context) = tree.withType(ExprType(result.tpe)) -- cgit v1.2.3