Skip to content

Commit cba5398

Browse files
committed
Add name span to SelectionProto
1 parent 12c88bc commit cba5398

File tree

8 files changed

+48
-48
lines changed

8 files changed

+48
-48
lines changed

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/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ trait Applications extends Compatibility {
976976
val resultType =
977977
if !originalResultType.isRef(defn.ObjectClass) then originalResultType
978978
else AvoidWildcardsMap()(proto.resultType.deepenProtoTrans) match
979-
case SelectionProto(nme.asInstanceOf_, PolyProto(_, resTp), _, _) => resTp
979+
case SelectionProto(nme.asInstanceOf_, PolyProto(_, resTp), _, _, _) => resTp
980980
case resTp if isFullyDefined(resTp, ForceDegree.all) => resTp
981981
case _ => defn.ObjectType
982982
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._
@@ -275,7 +276,7 @@ object ErrorReporting {
275276
else
276277
val add = suggestImports(
277278
ViewProto(qualType.widen,
278-
SelectionProto(tree.name, WildcardType, NoViewsAllowed, privateOK = false)))
279+
SelectionProto(tree.name, WildcardType, NoViewsAllowed, privateOK = false, NoSpan)))
279280
if add.isEmpty then ""
280281
else ", but could be made available as an extension method." ++ add
281282
end selectErrorAddendum

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ object Implicits:
7676
* method with the selecting name? False otherwise.
7777
*/
7878
def hasExtMethod(tp: Type, expected: Type)(using Context) = expected match
79-
case selProto @ SelectionProto(selName: TermName, _, _, _) =>
79+
case selProto @ SelectionProto(selName: TermName, _, _, _, _) =>
8080
tp.memberBasedOnFlags(selName, required = ExtensionMethod).exists
8181
case _ =>
8282
false
@@ -454,7 +454,7 @@ object Implicits:
454454
def clarify(tp: Type)(using Context): Type = tp
455455

456456
final protected def qualify(using Context): String = expectedType match {
457-
case SelectionProto(name, mproto, _, _) if !argument.isEmpty =>
457+
case SelectionProto(name, mproto, _, _, _) if !argument.isEmpty =>
458458
i"provide an extension method `$name` on ${argument.tpe}"
459459
case NoType =>
460460
if (argument.isEmpty) i"match expected type"
@@ -860,14 +860,14 @@ trait Implicits:
860860
/** Find an implicit conversion to apply to given tree `from` so that the
861861
* result is compatible with type `to`.
862862
*/
863-
def inferView(from: Tree, to: Type, nameSpan: Span = NoSpan)(using Context): SearchResult = {
863+
def inferView(from: Tree, to: Type)(using Context): SearchResult = {
864864
record("inferView")
865865
if !ctx.mode.is(Mode.ImplicitsEnabled) || from.isInstanceOf[Super] then
866866
NoMatchingImplicitsFailure
867867
else {
868868
def adjust(to: Type) = to.stripTypeVar.widenExpr match {
869-
case SelectionProto(name, memberProto, compat, true) =>
870-
SelectionProto(name, memberProto, compat, privateOK = false)
869+
case SelectionProto(name, memberProto, compat, true, nameSpan) =>
870+
SelectionProto(name, memberProto, compat, privateOK = false, nameSpan)
871871
case tp => tp
872872
}
873873

@@ -878,7 +878,7 @@ trait Implicits:
878878
}
879879

880880
try
881-
val inferred = inferImplicit(adjust(to), from, from.span, nameSpan)
881+
val inferred = inferImplicit(adjust(to), from, from.span)
882882

883883
inferred match {
884884
case SearchSuccess(_, ref, _, false) if isOldStyleFunctionConversion(ref.underlying) =>
@@ -1059,7 +1059,7 @@ trait Implicits:
10591059
* it should be applied, EmptyTree otherwise.
10601060
* @param span The position where errors should be reported.
10611061
*/
1062-
def inferImplicit(pt: Type, argument: Tree, span: Span, nameSpan: Span = NoSpan)(using Context): SearchResult =
1062+
def inferImplicit(pt: Type, argument: Tree, span: Span)(using Context): SearchResult =
10631063
trace(s"search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}", implicits, show = true) {
10641064
record("inferImplicit")
10651065
assert(ctx.phase.allowsImplicitSearch,
@@ -1082,7 +1082,7 @@ trait Implicits:
10821082
(searchCtx.scope eq ctx.scope) && (searchCtx.owner eq ctx.owner.owner)
10831083
do ()
10841084

1085-
try ImplicitSearch(pt, argument, span, nameSpan)(using searchCtx).bestImplicit
1085+
try ImplicitSearch(pt, argument, span)(using searchCtx).bestImplicit
10861086
catch case ce: CyclicReference =>
10871087
ce.inImplicitSearch = true
10881088
throw ce
@@ -1102,9 +1102,9 @@ trait Implicits:
11021102
result
11031103
case result: SearchFailure if result.isAmbiguous =>
11041104
val deepPt = pt.deepenProto
1105-
if (deepPt ne pt) inferImplicit(deepPt, argument, span, nameSpan)
1105+
if (deepPt ne pt) inferImplicit(deepPt, argument, span)
11061106
else if (migrateTo3 && !ctx.mode.is(Mode.OldOverloadingResolution))
1107-
withMode(Mode.OldOverloadingResolution)(inferImplicit(pt, argument, span, nameSpan)) match {
1107+
withMode(Mode.OldOverloadingResolution)(inferImplicit(pt, argument, span)) match {
11081108
case altResult: SearchSuccess =>
11091109
report.migrationWarning(
11101110
result.reason.msg
@@ -1125,7 +1125,7 @@ trait Implicits:
11251125
}
11261126

11271127
/** Try to typecheck an implicit reference */
1128-
def typedImplicit(cand: Candidate, pt: Type, argument: Tree, span: Span, nameSpan: Span = NoSpan)(using Context): SearchResult = trace(i"typed implicit ${cand.ref}, pt = $pt, implicitsEnabled == ${ctx.mode is ImplicitsEnabled}", implicits, show = true) {
1128+
def typedImplicit(cand: Candidate, pt: Type, argument: Tree, span: Span)(using Context): SearchResult = trace(i"typed implicit ${cand.ref}, pt = $pt, implicitsEnabled == ${ctx.mode is ImplicitsEnabled}", implicits, show = true) {
11291129
if ctx.run.nn.isCancelled then NoMatchingImplicitsFailure
11301130
else
11311131
record("typedImplicit")
@@ -1161,12 +1161,10 @@ trait Implicits:
11611161
pt, locked)
11621162
}
11631163
pt match
1164-
case selProto @ SelectionProto(selName: TermName, mbrType, _, _) =>
1164+
case selProto @ SelectionProto(selName: TermName, mbrType, _, _, nameSpan) =>
11651165

11661166
def tryExtension(using Context) =
1167-
val select0 = untpd.Select(untpdGenerated, selName)
1168-
val select = if nameSpan.exists then select0.withSpan(nameSpan) else select0
1169-
extMethodApply(select, argument, mbrType)
1167+
extMethodApply(untpd.Select(untpdGenerated, selName).withSpan(nameSpan), argument, mbrType)
11701168

11711169
def tryConversionForSelection(using Context) =
11721170
val converted = tryConversion
@@ -1217,7 +1215,7 @@ trait Implicits:
12171215
}
12181216

12191217
/** An implicit search; parameters as in `inferImplicit` */
1220-
class ImplicitSearch(protected val pt: Type, protected val argument: Tree, span: Span, nameSpan: Span = NoSpan)(using Context):
1218+
class ImplicitSearch(protected val pt: Type, protected val argument: Tree, span: Span)(using Context):
12211219
assert(argument.isEmpty || argument.tpe.isValueType || argument.tpe.isInstanceOf[ExprType],
12221220
em"found: $argument: ${argument.tpe}, expected: $pt")
12231221

@@ -1266,7 +1264,7 @@ trait Implicits:
12661264
val history = ctx.searchHistory.nest(cand, pt)
12671265
val typingCtx =
12681266
nestedContext().setNewTyperState().setFreshGADTBounds.setSearchHistory(history)
1269-
val result = typedImplicit(cand, pt, argument, span, nameSpan)(using typingCtx)
1267+
val result = typedImplicit(cand, pt, argument, span)(using typingCtx)
12701268
result match
12711269
case res: SearchSuccess =>
12721270
ctx.searchHistory.defineBynameImplicit(wideProto, res)

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
@@ -21,6 +21,7 @@ import dotty.tools.dotc.core.Flags.Transparent
2121
import dotty.tools.dotc.config.{ Feature, SourceVersion }
2222

2323
import scala.annotation.internal.sharable
24+
import dotty.tools.dotc.util.Spans.{NoSpan, Span}
2425

2526
object ProtoTypes {
2627

@@ -180,7 +181,7 @@ object ProtoTypes {
180181
*
181182
* [ ].name: proto
182183
*/
183-
abstract case class SelectionProto(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean)
184+
abstract case class SelectionProto(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean, nameSpan: Span)
184185
extends CachedProxyType with ProtoType with ValueTypeOrProto {
185186

186187
/** Is the set of members of this type unknown, in the sense that we
@@ -243,24 +244,24 @@ object ProtoTypes {
243244

244245
def underlying(using Context): Type = WildcardType
245246

246-
def derivedSelectionProto(name: Name, memberProto: Type, compat: Compatibility)(using Context): SelectionProto =
247-
if ((name eq this.name) && (memberProto eq this.memberProto) && (compat eq this.compat)) this
248-
else SelectionProto(name, memberProto, compat, privateOK)
247+
def derivedSelectionProto(name: Name, memberProto: Type, compat: Compatibility, nameSpan: Span)(using Context): SelectionProto =
248+
if ((name eq this.name) && (memberProto eq this.memberProto) && (compat eq this.compat) && (nameSpan == this.nameSpan)) this
249+
else SelectionProto(name, memberProto, compat, privateOK, nameSpan)
249250

250251
override def isErroneous(using Context): Boolean =
251252
memberProto.isErroneous
252253

253254
override def unusableForInference(using Context): Boolean =
254255
memberProto.unusableForInference
255256

256-
def map(tm: TypeMap)(using Context): SelectionProto = derivedSelectionProto(name, tm(memberProto), compat)
257+
def map(tm: TypeMap)(using Context): SelectionProto = derivedSelectionProto(name, tm(memberProto), compat, nameSpan)
257258
def fold[T](x: T, ta: TypeAccumulator[T])(using Context): T = ta(x, memberProto)
258259

259260
override def deepenProto(using Context): SelectionProto =
260-
derivedSelectionProto(name, memberProto.deepenProto, compat)
261+
derivedSelectionProto(name, memberProto.deepenProto, compat, nameSpan)
261262

262263
override def deepenProtoTrans(using Context): SelectionProto =
263-
derivedSelectionProto(name, memberProto.deepenProtoTrans, compat)
264+
derivedSelectionProto(name, memberProto.deepenProtoTrans, compat, nameSpan)
264265

265266
override def computeHash(bs: Hashable.Binders): Int = {
266267
val delta = (if (compat eq NoViewsAllowed) 1 else 0) | (if (privateOK) 2 else 0)
@@ -281,24 +282,24 @@ object ProtoTypes {
281282
}
282283
}
283284

284-
class CachedSelectionProto(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean)
285-
extends SelectionProto(name, memberProto, compat, privateOK)
285+
class CachedSelectionProto(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean, nameSpan: Span)
286+
extends SelectionProto(name, memberProto, compat, privateOK, nameSpan)
286287

287288
object SelectionProto {
288-
def apply(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean)(using Context): SelectionProto = {
289-
val selproto = new CachedSelectionProto(name, memberProto, compat, privateOK)
289+
def apply(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean, nameSpan: Span)(using Context): SelectionProto = {
290+
val selproto = new CachedSelectionProto(name, memberProto, compat, privateOK, nameSpan)
290291
if (compat eq NoViewsAllowed) unique(selproto) else selproto
291292
}
292293
}
293294

294295
/** Create a selection proto-type, but only one level deep;
295296
* treat constructors specially
296297
*/
297-
def shallowSelectionProto(name: Name, tp: Type, typer: Typer)(using Context): TermType =
298+
def shallowSelectionProto(name: Name, tp: Type, typer: Typer, nameSpan: Span)(using Context): TermType =
298299
if (name.isConstructorName) WildcardType
299300
else tp match
300-
case tp: UnapplyFunProto => new UnapplySelectionProto(name)
301-
case tp => SelectionProto(name, IgnoredProto(tp), typer, privateOK = true)
301+
case tp: UnapplyFunProto => new UnapplySelectionProto(name, nameSpan)
302+
case tp => SelectionProto(name, IgnoredProto(tp), typer, privateOK = true, nameSpan)
302303

303304
/** A prototype for expressions [] that are in some unspecified selection operation
304305
*
@@ -308,12 +309,12 @@ object ProtoTypes {
308309
* operation is further selection. In this case, the expression need not be a value.
309310
* @see checkValue
310311
*/
311-
@sharable object AnySelectionProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true)
312+
@sharable object AnySelectionProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true, NoSpan)
312313

313-
@sharable object SingletonTypeProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true)
314+
@sharable object SingletonTypeProto extends SelectionProto(nme.WILDCARD, WildcardType, NoViewsAllowed, true, NoSpan)
314315

315316
/** A prototype for selections in pattern constructors */
316-
class UnapplySelectionProto(name: Name) extends SelectionProto(name, WildcardType, NoViewsAllowed, true)
317+
class UnapplySelectionProto(name: Name, nameSpan: Span) extends SelectionProto(name, WildcardType, NoViewsAllowed, true, nameSpan)
317318

318319
trait ApplyingProto extends ProtoType // common trait of ViewProto and FunProto
319320
trait FunOrPolyProto extends ProtoType: // common trait of PolyProto and FunProto
@@ -612,7 +613,7 @@ object ProtoTypes {
612613
def isMatchedBy(tp: Type, keepConstraint: Boolean)(using Context): Boolean =
613614
ctx.typer.isApplicableType(tp, argType :: Nil, resultType) || {
614615
resType match {
615-
case selProto @ SelectionProto(selName: TermName, mbrType, _, _) =>
616+
case selProto @ SelectionProto(selName: TermName, mbrType, _, _, _) =>
616617
ctx.typer.hasExtensionMethodNamed(tp, selName, argType, mbrType)
617618
//.reporting(i"has ext $tp $name $argType $mbrType: $result")
618619
case _ =>
@@ -934,7 +935,7 @@ object ProtoTypes {
934935
}
935936
approxOr
936937
case tp: SelectionProto =>
937-
tp.derivedSelectionProto(tp.name, wildApprox(tp.memberProto, theMap, seen, internal), NoViewsAllowed)
938+
tp.derivedSelectionProto(tp.name, wildApprox(tp.memberProto, theMap, seen, internal), NoViewsAllowed, tp.nameSpan)
938939
case tp: ViewProto =>
939940
tp.derivedViewProto(
940941
wildApprox(tp.argType, theMap, seen, internal),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Decorators._
1010
import typer.ProtoTypes._
1111
import ast.{tpd, untpd}
1212
import scala.util.control.NonFatal
13-
import util.Spans.{NoSpan, Span}
13+
import util.Spans.Span
1414
import Nullables._
1515
import staging.StagingLevel.*
1616

@@ -179,7 +179,7 @@ class ReTyper(nestingLevel: Int = 0) extends Typer(nestingLevel) with ReChecking
179179

180180
override def inlineExpansion(mdef: DefDef)(using Context): List[Tree] = mdef :: Nil
181181

182-
override def inferView(from: Tree, to: Type, nameSpan: Span = NoSpan)(using Context): Implicits.SearchResult =
182+
override def inferView(from: Tree, to: Type)(using Context): Implicits.SearchResult =
183183
Implicits.NoMatchingImplicitsFailure
184184
override def checkCanEqual(ltp: Type, rtp: Type, span: Span)(using Context): Unit = ()
185185

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
760760
record("typedSelect")
761761

762762
def typeSelectOnTerm(using Context): Tree =
763-
val qual = typedExpr(tree.qualifier, shallowSelectionProto(tree.name, pt, this))
763+
val qual = typedExpr(tree.qualifier, shallowSelectionProto(tree.name, pt, this, tree.nameSpan))
764764
typedSelect(tree, pt, qual).withSpan(tree.span).computeNullable()
765765

766766
def javaSelectOnType(qual: Tree)(using Context) =
@@ -790,7 +790,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
790790
tryAlternatively(typeSelectOnTerm)(fallBack)
791791

792792
if (tree.qualifier.isType) {
793-
val qual1 = typedType(tree.qualifier, shallowSelectionProto(tree.name, pt, this))
793+
val qual1 = typedType(tree.qualifier, shallowSelectionProto(tree.name, pt, this, tree.nameSpan))
794794
assignType(cpy.Select(tree)(qual1, tree.name), qual1)
795795
}
796796
else if (ctx.isJava && tree.name.isTypeName)
@@ -3513,7 +3513,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
35133513
then
35143514
Some(adapt(tree, pt, locked))
35153515
else
3516-
val selProto = SelectionProto(name, pt, NoViewsAllowed, privateOK = false)
3516+
val selProto = SelectionProto(name, pt, NoViewsAllowed, privateOK = false, tree.nameSpan)
35173517
if selProto.isMatchedBy(qual.tpe) || tree.hasAttachment(InsertedImplicitOnQualifier) then
35183518
None
35193519
else
@@ -3538,7 +3538,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
35383538
(tree: untpd.Select, pt: Type, mbrProto: Type, qual: Tree, locked: TypeVars, compat: Compatibility, inSelect: Boolean)
35393539
(using Context): Tree =
35403540

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

35433543
def tryExtension(using Context): Tree =
35443544
val altImports = new mutable.ListBuffer[TermRef]()
@@ -3598,7 +3598,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
35983598
if ctx.mode.is(Mode.ImplicitsEnabled) && !tree.name.isConstructorName && qual.tpe.isValueType then
35993599
try
36003600
val selProto = selectionProto
3601-
trace(i"try insert impl on qualifier $tree $pt") { inferView(qual, selProto, tree.nameSpan) } match
3601+
trace(i"try insert impl on qualifier $tree $pt") { inferView(qual, selProto) } match
36023602
case SearchSuccess(found, _, _, isExtension) =>
36033603
if isExtension then return found
36043604
else
@@ -3968,7 +3968,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39683968
* function prototype `(...)R`. Otherwise `pt`.
39693969
*/
39703970
def ptWithoutRedundantApply: Type = pt.revealIgnored match
3971-
case SelectionProto(nme.apply, mpt, _, _) =>
3971+
case SelectionProto(nme.apply, mpt, _, _, _) =>
39723972
mpt.revealIgnored match
39733973
case fpt: FunProto => fpt
39743974
case _ => pt

0 commit comments

Comments
 (0)