Skip to content

Commit

Permalink
Add comment explaining why remove variance, use Name#startsWith ins…
Browse files Browse the repository at this point in the history
…tead of `.lastPart.startsWith`
  • Loading branch information
neko-kai committed May 5, 2021
1 parent 4295d3c commit fe8ebd7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,11 @@ object Parsers {
}

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

0 comments on commit fe8ebd7

Please sign in to comment.