Skip to content

Commit beb027c

Browse files
Backport "bugfix: highlight for enum type params" to LTS (#20614)
Backports #18528 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 2ed285b + 34093be commit beb027c

30 files changed

+528
-197
lines changed

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ object MainGenericRunner {
148148
case (o @ javaOption(striped)) :: tail =>
149149
processArgs(tail, settings.withJavaArgs(striped).withScalaArgs(o))
150150
case (o @ scalaOption(_*)) :: tail =>
151-
val remainingArgs = (CommandLineParser.expandArg(o) ++ tail).toList
151+
val remainingArgs = CommandLineParser.expandArg(o) ++ tail
152152
processArgs(remainingArgs, settings)
153153
case (o @ colorOption(_*)) :: tail =>
154154
processArgs(tail, settings.withScalaArgs(o))

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ object Trees {
455455
val point = span.point
456456
if name.toTermName == nme.ERROR then
457457
Span(point)
458-
else if qualifier.span.start > span.start then // right associative
458+
else if qualifier.span.start > span.point then // right associative
459459
val realName = name.stripModuleClassSuffix.lastPart
460460
Span(span.start, span.start + realName.length, point)
461461
else

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,8 +2130,11 @@ class Definitions {
21302130
this.initCtx = ctx
21312131
if (!isInitialized) {
21322132
// force initialization of every symbol that is synthesized or hijacked by the compiler
2133-
val forced =
2134-
syntheticCoreClasses ++ syntheticCoreMethods ++ ScalaValueClasses() :+ JavaEnumClass
2133+
syntheticCoreClasses
2134+
syntheticCoreMethods
2135+
ScalaValueClasses()
2136+
JavaEnumClass
2137+
// end force initialization
21352138
isInitialized = true
21362139
}
21372140
addSyntheticSymbolsComments

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ class Inliner(val call: tpd.Tree)(using Context):
771771

772772
override def typedSelect(tree: untpd.Select, pt: Type)(using Context): Tree = {
773773
val locked = ctx.typerState.ownedVars
774-
val qual1 = typed(tree.qualifier, shallowSelectionProto(tree.name, pt, this))
774+
val qual1 = typed(tree.qualifier, shallowSelectionProto(tree.name, pt, this, tree.nameSpan))
775775
val resNoReduce = untpd.cpy.Select(tree)(qual1, tree.name).withType(tree.typeOpt)
776776
val reducedProjection = reducer.reduceProjection(resNoReduce)
777777
if reducedProjection.isType then

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,12 @@ class ExtractSemanticDB extends Phase:
392392
}).toMap
393393
end findGetters
394394

395-
private def selectSpan(tree: Select) =
395+
private def selectSpan(tree: Select)(using Context) =
396396
val end = tree.span.end
397397
val limit = tree.qualifier.span.end
398-
val start =
399-
if limit < end then
400-
val len = tree.name.toString.length
401-
if tree.source.content()(end - 1) == '`' then end - len - 2 else end - len
402-
else limit
403-
Span(start max limit, end)
398+
if limit < end then
399+
tree.nameSpan
400+
else Span(limit, end)
404401

405402
extension (span: Span)
406403
private def hasLength: Boolean = span.exists && !span.isZeroExtent

compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class SemanticSymbolBuilder:
8484
else
8585
decls0
8686
end decls
87-
val alts = decls.filter(_.isOneOf(Method | Mutable)).toList.reverse
87+
val alts = decls.filter(_.isOneOf(Method | Mutable)).toList.reverse.partition(!_.is(Synthetic)).toList.flatten
8888
def find(filter: Symbol => Boolean) = alts match
8989
case notSym :: rest if !filter(notSym) =>
9090
val idx = rest.indexWhere(filter).ensuring(_ >= 0)

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,19 @@ object CheckUnused:
561561
else
562562
Nil
563563
val warnings =
564-
List(sortedImp, sortedLocalDefs, sortedExplicitParams, sortedImplicitParams,
565-
sortedPrivateDefs, sortedPatVars, unsetLocalDefs, unsetPrivateDefs).flatten.sortBy { s =>
566-
val pos = s.pos.sourcePos
567-
(pos.line, pos.column)
568-
}
564+
val unsorted =
565+
sortedImp :::
566+
sortedLocalDefs :::
567+
sortedExplicitParams :::
568+
sortedImplicitParams :::
569+
sortedPrivateDefs :::
570+
sortedPatVars :::
571+
unsetLocalDefs :::
572+
unsetPrivateDefs
573+
unsorted.sortBy { s =>
574+
val pos = s.pos.sourcePos
575+
(pos.line, pos.column)
576+
}
569577
UnusedResult(warnings.toSet)
570578
end getUnused
571579
//============================ HELPERS ====================================

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ trait Applications extends Compatibility {
959959
val resultType =
960960
if !originalResultType.isRef(defn.ObjectClass) then originalResultType
961961
else AvoidWildcardsMap()(proto.resultType.deepenProtoTrans) match
962-
case SelectionProto(nme.asInstanceOf_, PolyProto(_, resTp), _, _) => resTp
962+
case SelectionProto(nme.asInstanceOf_, PolyProto(_, resTp), _, _, _) => resTp
963963
case resTp if isFullyDefined(resTp, ForceDegree.all) => resTp
964964
case _ => defn.ObjectType
965965
val methType = MethodType(proto.typedArgs().map(_.tpe.widen), resultType)

compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Types._, ProtoTypes._, Contexts._, Decorators._, Denotations._, Symbols._
88
import Implicits._, Flags._, Constants.Constant
99
import Trees._
1010
import NameOps._
11+
import util.Spans.NoSpan
1112
import util.SrcPos
1213
import config.Feature
1314
import reporting._
@@ -266,7 +267,7 @@ object ErrorReporting {
266267
else
267268
val add = suggestImports(
268269
ViewProto(qualType.widen,
269-
SelectionProto(tree.name, WildcardType, NoViewsAllowed, privateOK = false)))
270+
SelectionProto(tree.name, WildcardType, NoViewsAllowed, privateOK = false, NoSpan)))
270271
if add.isEmpty then ""
271272
else ", but could be made available as an extension method." ++ add
272273
end selectErrorAddendum

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ object Implicits:
7575
* method with the selecting name? False otherwise.
7676
*/
7777
def hasExtMethod(tp: Type, expected: Type)(using Context) = expected match
78-
case selProto @ SelectionProto(selName: TermName, _, _, _) =>
78+
case selProto @ SelectionProto(selName: TermName, _, _, _, _) =>
7979
tp.memberBasedOnFlags(selName, required = ExtensionMethod).exists
8080
case _ =>
8181
false
@@ -437,7 +437,7 @@ object Implicits:
437437
def clarify(tp: Type)(using Context): Type = tp
438438

439439
final protected def qualify(using Context): String = expectedType match {
440-
case SelectionProto(name, mproto, _, _) if !argument.isEmpty =>
440+
case SelectionProto(name, mproto, _, _, _) if !argument.isEmpty =>
441441
i"provide an extension method `$name` on ${argument.tpe}"
442442
case NoType =>
443443
if (argument.isEmpty) i"match expected type"
@@ -842,8 +842,8 @@ trait Implicits:
842842
NoMatchingImplicitsFailure
843843
else {
844844
def adjust(to: Type) = to.stripTypeVar.widenExpr match {
845-
case SelectionProto(name, memberProto, compat, true) =>
846-
SelectionProto(name, memberProto, compat, privateOK = false)
845+
case SelectionProto(name, memberProto, compat, true, nameSpan) =>
846+
SelectionProto(name, memberProto, compat, privateOK = false, nameSpan)
847847
case tp => tp
848848
}
849849

@@ -1137,10 +1137,10 @@ trait Implicits:
11371137
pt, locked)
11381138
}
11391139
pt match
1140-
case selProto @ SelectionProto(selName: TermName, mbrType, _, _) =>
1140+
case selProto @ SelectionProto(selName: TermName, mbrType, _, _, nameSpan) =>
11411141

11421142
def tryExtension(using Context) =
1143-
extMethodApply(untpd.Select(untpdGenerated, selName), argument, mbrType)
1143+
extMethodApply(untpd.Select(untpdGenerated, selName).withSpan(nameSpan), argument, mbrType)
11441144

11451145
def tryConversionForSelection(using Context) =
11461146
val converted = tryConversion

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ trait ImportSuggestions:
237237
// don't suggest things that are imported by default
238238

239239
def extensionImports = pt match
240-
case ViewProto(argType, SelectionProto(name: TermName, _, _, _)) =>
240+
case ViewProto(argType, SelectionProto(name: TermName, _, _, _, _)) =>
241241
roots.flatMap(extensionMethod(_, name, argType))
242242
case _ =>
243243
Nil

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import util.SourceFile
1919
import TypeComparer.necessarySubType
2020

2121
import scala.annotation.internal.sharable
22+
import dotty.tools.dotc.util.Spans.{NoSpan, Span}
2223

2324
object ProtoTypes {
2425

@@ -165,7 +166,7 @@ object ProtoTypes {
165166
*
166167
* [ ].name: proto
167168
*/
168-
abstract case class SelectionProto(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean)
169+
abstract case class SelectionProto(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean, nameSpan: Span)
169170
extends CachedProxyType with ProtoType with ValueTypeOrProto {
170171

171172
/** Is the set of members of this type unknown, in the sense that we
@@ -230,24 +231,24 @@ object ProtoTypes {
230231

231232
def underlying(using Context): Type = WildcardType
232233

233-
def derivedSelectionProto(name: Name, memberProto: Type, compat: Compatibility)(using Context): SelectionProto =
234-
if ((name eq this.name) && (memberProto eq this.memberProto) && (compat eq this.compat)) this
235-
else SelectionProto(name, memberProto, compat, privateOK)
234+
def derivedSelectionProto(name: Name, memberProto: Type, compat: Compatibility, nameSpan: Span)(using Context): SelectionProto =
235+
if ((name eq this.name) && (memberProto eq this.memberProto) && (compat eq this.compat) && (nameSpan == this.nameSpan)) this
236+
else SelectionProto(name, memberProto, compat, privateOK, nameSpan)
236237

237238
override def isErroneous(using Context): Boolean =
238239
memberProto.isErroneous
239240

240241
override def unusableForInference(using Context): Boolean =
241242
memberProto.unusableForInference
242243

243-
def map(tm: TypeMap)(using Context): SelectionProto = derivedSelectionProto(name, tm(memberProto), compat)
244+
def map(tm: TypeMap)(using Context): SelectionProto = derivedSelectionProto(name, tm(memberProto), compat, nameSpan)
244245
def fold[T](x: T, ta: TypeAccumulator[T])(using Context): T = ta(x, memberProto)
245246

246247
override def deepenProto(using Context): SelectionProto =
247-
derivedSelectionProto(name, memberProto.deepenProto, compat)
248+
derivedSelectionProto(name, memberProto.deepenProto, compat, nameSpan)
248249

249250
override def deepenProtoTrans(using Context): SelectionProto =
250-
derivedSelectionProto(name, memberProto.deepenProtoTrans, compat)
251+
derivedSelectionProto(name, memberProto.deepenProtoTrans, compat, nameSpan)
251252

252253
override def computeHash(bs: Hashable.Binders): Int = {
253254
val delta = (if (compat eq NoViewsAllowed) 1 else 0) | (if (privateOK) 2 else 0)
@@ -268,24 +269,24 @@ object ProtoTypes {
268269
}
269270
}
270271

271-
class CachedSelectionProto(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean)
272-
extends SelectionProto(name, memberProto, compat, privateOK)
272+
class CachedSelectionProto(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean, nameSpan: Span)
273+
extends SelectionProto(name, memberProto, compat, privateOK, nameSpan)
273274

274275
object SelectionProto {
275-
def apply(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean)(using Context): SelectionProto = {
276-
val selproto = new CachedSelectionProto(name, memberProto, compat, privateOK)
276+
def apply(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean, nameSpan: Span)(using Context): SelectionProto = {
277+
val selproto = new CachedSelectionProto(name, memberProto, compat, privateOK, nameSpan)
277278
if (compat eq NoViewsAllowed) unique(selproto) else selproto
278279
}
279280
}
280281

281282
/** Create a selection proto-type, but only one level deep;
282283
* treat constructors specially
283284
*/
284-
def shallowSelectionProto(name: Name, tp: Type, typer: Typer)(using Context): TermType =
285+
def shallowSelectionProto(name: Name, tp: Type, typer: Typer, nameSpan: Span)(using Context): TermType =
285286
if (name.isConstructorName) WildcardType
286287
else tp match
287-
case tp: UnapplyFunProto => new UnapplySelectionProto(name)
288-
case tp => SelectionProto(name, IgnoredProto(tp), typer, privateOK = true)
288+
case tp: UnapplyFunProto => new UnapplySelectionProto(name, nameSpan)
289+
case tp => SelectionProto(name, IgnoredProto(tp), typer, privateOK = true, nameSpan)
289290

290291
/** A prototype for expressions [] that are in some unspecified selection operation
291292
*
@@ -295,12 +296,12 @@ object ProtoTypes {
295296
* operation is further selection. In this case, the expression need not be a value.
296297
* @see checkValue
297298
*/
298-
@sharable object AnySelectionProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true)
299+
@sharable object AnySelectionProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true, NoSpan)
299300

300-
@sharable object SingletonTypeProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true)
301+
@sharable object SingletonTypeProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true, NoSpan)
301302

302303
/** A prototype for selections in pattern constructors */
303-
class UnapplySelectionProto(name: Name) extends SelectionProto(name, WildcardType, NoViewsAllowed, true)
304+
class UnapplySelectionProto(name: Name, nameSpan: Span) extends SelectionProto(name, WildcardType, NoViewsAllowed, true, nameSpan)
304305

305306
trait ApplyingProto extends ProtoType // common trait of ViewProto and FunProto
306307
trait FunOrPolyProto extends ProtoType: // common trait of PolyProto and FunProto
@@ -599,7 +600,7 @@ object ProtoTypes {
599600
def isMatchedBy(tp: Type, keepConstraint: Boolean)(using Context): Boolean =
600601
ctx.typer.isApplicableType(tp, argType :: Nil, resultType) || {
601602
resType match {
602-
case selProto @ SelectionProto(selName: TermName, mbrType, _, _) =>
603+
case selProto @ SelectionProto(selName: TermName, mbrType, _, _, _) =>
603604
ctx.typer.hasExtensionMethodNamed(tp, selName, argType, mbrType)
604605
//.reporting(i"has ext $tp $name $argType $mbrType: $result")
605606
case _ =>
@@ -921,7 +922,7 @@ object ProtoTypes {
921922
}
922923
approxOr
923924
case tp: SelectionProto =>
924-
tp.derivedSelectionProto(tp.name, wildApprox(tp.memberProto, theMap, seen, internal), NoViewsAllowed)
925+
tp.derivedSelectionProto(tp.name, wildApprox(tp.memberProto, theMap, seen, internal), NoViewsAllowed, tp.nameSpan)
925926
case tp: ViewProto =>
926927
tp.derivedViewProto(
927928
wildApprox(tp.argType, theMap, seen, internal),

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
752752
record("typedSelect")
753753

754754
def typeSelectOnTerm(using Context): Tree =
755-
val qual = typedExpr(tree.qualifier, shallowSelectionProto(tree.name, pt, this))
755+
val qual = typedExpr(tree.qualifier, shallowSelectionProto(tree.name, pt, this, tree.nameSpan))
756756
typedSelect(tree, pt, qual).withSpan(tree.span).computeNullable()
757757

758758
def javaSelectOnType(qual: Tree)(using Context) =
@@ -782,7 +782,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
782782
tryAlternatively(typeSelectOnTerm)(fallBack)
783783

784784
if (tree.qualifier.isType) {
785-
val qual1 = typedType(tree.qualifier, shallowSelectionProto(tree.name, pt, this))
785+
val qual1 = typedType(tree.qualifier, shallowSelectionProto(tree.name, pt, this, tree.nameSpan))
786786
assignType(cpy.Select(tree)(qual1, tree.name), qual1)
787787
}
788788
else if (ctx.isJava && tree.name.isTypeName)
@@ -3442,7 +3442,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
34423442
then
34433443
Some(adapt(tree, pt, locked))
34443444
else
3445-
val selProto = SelectionProto(name, pt, NoViewsAllowed, privateOK = false)
3445+
val selProto = SelectionProto(name, pt, NoViewsAllowed, privateOK = false, tree.nameSpan)
34463446
if selProto.isMatchedBy(qual.tpe) || tree.hasAttachment(InsertedImplicitOnQualifier) then
34473447
None
34483448
else
@@ -3467,7 +3467,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
34673467
(tree: untpd.Select, pt: Type, mbrProto: Type, qual: Tree, locked: TypeVars, compat: Compatibility, inSelect: Boolean)
34683468
(using Context): Tree =
34693469

3470-
def selectionProto = SelectionProto(tree.name, mbrProto, compat, privateOK = inSelect)
3470+
def selectionProto = SelectionProto(tree.name, mbrProto, compat, privateOK = inSelect, tree.nameSpan)
34713471

34723472
def tryExtension(using Context): Tree =
34733473
val altImports = new mutable.ListBuffer[TermRef]()
@@ -3897,7 +3897,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38973897
* function prototype `(...)R`. Otherwise `pt`.
38983898
*/
38993899
def ptWithoutRedundantApply: Type = pt.revealIgnored match
3900-
case SelectionProto(nme.apply, mpt, _, _) =>
3900+
case SelectionProto(nme.apply, mpt, _, _, _) =>
39013901
mpt.revealIgnored match
39023902
case fpt: FunProto => fpt
39033903
case _ => pt

0 commit comments

Comments
 (0)