Skip to content

Commit fe8ebd7

Browse files
committed
Add comment explaining why remove variance, use Name#startsWith instead of .lastPart.startsWith
1 parent 4295d3c commit fe8ebd7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,11 @@ object Parsers {
14481448
}
14491449

14501450
private def makeKindProjectorTypeDef(name: TypeName): TypeDef = {
1451-
val isVarianceAnnotated = name.lastPart.startsWith("+") || name.lastPart.startsWith("-")
1451+
val isVarianceAnnotated = name.startsWith("+") || name.startsWith("-")
1452+
// We remove the variance marker from the name without passing along the specified variance at all
1453+
// The real variance will be inferred at a later stage but may contradict the variance specified,
1454+
// This is ok, because `-Ykind-projector` is for cross-compiling existing Scala 2 code, not for writing new code,
1455+
// we may assume that variance annotations have already been checked by the Scala 2 compiler.
14521456
val unannotatedName = if (isVarianceAnnotated) name.mapLast(_.drop(1)) else name
14531457
TypeDef(unannotatedName, WildcardTypeBoundsTree()).withFlags(Param)
14541458
}

0 commit comments

Comments
 (0)