summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-12-03 12:32:59 +0100
committerJason Zaugg <jzaugg@gmail.com>2013-12-03 13:03:39 +0100
commitd0aaa86a9fe20e00f0cfa4fd1154126579933fb7 (patch)
treea9a27a4b18b7f6d2d79a578b1566761b0f8005ba /src/compiler
parenta89000be9f5b6506bcd891bd076700a9d1e79d01 (diff)
downloadscala-d0aaa86a9fe20e00f0cfa4fd1154126579933fb7.tar.gz
scala-d0aaa86a9fe20e00f0cfa4fd1154126579933fb7.tar.bz2
scala-d0aaa86a9fe20e00f0cfa4fd1154126579933fb7.zip
SI-8023 Address review comments around typedHigherKindedType
- Make `WildCardType` kind polymorphic - Factory methods for expected kinds. They are still just `Type`-s, though. - Check if the type parameter is initialized, rather than its owner. - Take advantage of these to cleanup `typedAppliedTypeTree` TODO: is this comment totally accurate? If so, should we refactor `Kind.FromParams(tparams)` to `Kind.Arity(tparams.length)`? // @M: kind-arity checking is done here and in adapt, // full kind-checking is in checkKindBounds (in Infer)
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index a8d332f96a..c947fba37e 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -3835,7 +3835,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
// as we don't know which alternative to choose... here we do
map2Conserve(args, tparams) {
//@M! the polytype denotes the expected kind
- (arg, tparam) => typedHigherKindedType(arg, mode, GenPolyType(tparam.typeParams, AnyTpe))
+ (arg, tparam) => typedHigherKindedType(arg, mode, Kind.FromParams(tparam.typeParams))
}
} else // @M: there's probably something wrong when args.length != tparams.length... (triggered by bug #320)
// Martin, I'm using fake trees, because, if you use args or arg.map(typedType),
@@ -4880,20 +4880,17 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (sameLength(tparams, args)) {
// @M: kind-arity checking is done here and in adapt, full kind-checking is in checkKindBounds (in Infer)
val args1 = map2Conserve(args, tparams) { (arg, tparam) =>
- //@M! the polytype denotes the expected kind
- def pt = GenPolyType(tparam.typeParams, AnyTpe)
-
- // if symbol hasn't been fully loaded, can't check kind-arity
- // ... except, if we're in a pattern, where we can and must (SI-8023)
- if (mode.typingPatternOrTypePat) {
- tparam.initialize
- typedHigherKindedType(arg, mode, pt)
+ def ptParams = Kind.FromParams(tparam.typeParams)
+
+ // if symbol hasn't been fully loaded, can't check kind-arity except when we're in a pattern,
+ // where we can (we can't take part in F-Bounds) and must (SI-8023)
+ val pt = if (mode.typingPatternOrTypePat) {
+ tparam.initialize; ptParams
}
- else if (isComplete)
- typedHigherKindedType(arg, mode, pt)
- else
- // This overload (without pt) allows type constructors, as we don't don't know the allowed kind.
- typedHigherKindedType(arg, mode)
+ else if (isComplete) ptParams
+ else Kind.Wildcard
+
+ typedHigherKindedType(arg, mode, pt)
}
val argtypes = args1 map (_.tpe)
@@ -5080,8 +5077,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
// @M maybe the well-kindedness check should be done when checking the type arguments conform to the type parameters' bounds?
val args1 = if (sameLength(args, tparams)) map2Conserve(args, tparams) {
- //@M! the polytype denotes the expected kind
- (arg, tparam) => typedHigherKindedType(arg, mode, GenPolyType(tparam.typeParams, AnyTpe))
+ (arg, tparam) => typedHigherKindedType(arg, mode, Kind.FromParams(tparam.typeParams))
}
else {
//@M this branch is correctly hit for an overloaded polymorphic type. It also has to handle erroneous cases.
@@ -5451,9 +5447,9 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
/** Types a (fully parameterized) type tree */
def typedType(tree: Tree): Tree = typedType(tree, NOmode)
- /** Types a higher-kinded type tree -- pt denotes the expected kind*/
+ /** Types a higher-kinded type tree -- pt denotes the expected kind and must be one of `Kind.WildCard` and `Kind.FromParams` */
def typedHigherKindedType(tree: Tree, mode: Mode, pt: Type): Tree =
- if (pt.typeParams.isEmpty) typedType(tree, mode) // kind is known and it's *
+ if (pt != Kind.Wildcard && pt.typeParams.isEmpty) typedType(tree, mode) // kind is known and it's *
else context withinTypeConstructorAllowed typed(tree, NOmode, pt)
def typedHigherKindedType(tree: Tree, mode: Mode): Tree =