Skip to content

Commit 13a93c0

Browse files
committed
Fix rebase breakage
1 parent 3616eea commit 13a93c0

File tree

10 files changed

+49
-46
lines changed

10 files changed

+49
-46
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Symbols._, StdNames._, Trees._
88
import Decorators._, transform.SymUtils._
99
import NameKinds.{UniqueName, EvidenceParamName, DefaultGetterName}
1010
import typer.FrontEnd
11-
import util.{Property, SourceFile}
11+
import util.{Property, SourceFile, SourcePosition}
1212
import collection.mutable.ListBuffer
1313
import reporting.diagnostic.messages._
1414
import reporting.trace
@@ -29,7 +29,7 @@ object desugar {
2929
* The position value indicates the start position of the template of the
3030
* deriving class.
3131
*/
32-
val DerivingCompanion: Property.Key[Position] = new Property.Key
32+
val DerivingCompanion: Property.Key[SourcePosition] = new Property.Key
3333

3434
/** Info of a variable in a pattern: The named tree and its type */
3535
private type VarInfo = (NameTree, Tree)
@@ -578,7 +578,7 @@ object desugar {
578578
.withSpan(cdef.span).toList
579579
if (companionDerived.nonEmpty)
580580
for (modClsDef @ TypeDef(_, _) <- mdefs)
581-
modClsDef.putAttachment(DerivingCompanion, impl.pos.startPos)
581+
modClsDef.putAttachment(DerivingCompanion, impl.sourcePos.startPos)
582582
mdefs
583583
}
584584

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
315315
def ValDef(name: TermName, tpt: Tree, rhs: LazyTree)(implicit src: SourceFile): ValDef = new ValDef(name, tpt, rhs)
316316
def DefDef(name: TermName, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: LazyTree)(implicit src: SourceFile): DefDef = new DefDef(name, tparams, vparamss, tpt, rhs)
317317
def TypeDef(name: TypeName, rhs: Tree)(implicit src: SourceFile): TypeDef = new TypeDef(name, rhs)
318-
def Template(constr: DefDef, parents: List[Tree], self: ValDef, body: LazyTreeList)(implicit src: SourceFile): Template =
318+
def Template(constr: DefDef, parents: List[Tree], derived: List[Tree], self: ValDef, body: LazyTreeList)(implicit src: SourceFile): Template =
319319
if (derived.isEmpty) new Template(constr, parents, self, body)
320320
else new DerivingTemplate(constr, parents ++ derived, self, body, derived.length)
321321
def Import(expr: Tree, selectors: List[Tree])(implicit src: SourceFile): Import = new Import(expr, selectors)

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object Printers {
1818
val config: Printer = noPrinter
1919
val cyclicErrors: Printer = noPrinter
2020
val debug = noPrinter
21-
val derive = noPrinter
21+
val derive: Printer = noPrinter
2222
val dottydoc: Printer = noPrinter
2323
val exhaustivity: Printer = noPrinter
2424
val gadts: Printer = noPrinter

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import util.SourceFile
88
import java.lang.Character.isDigit
99
import scala.tasty.util.Chars._
1010
import util.NameTransformer.avoidIllegalChars
11+
import util.Spans.Span
1112
import Tokens._
1213
import scala.annotation.{ switch, tailrec }
1314
import scala.collection.mutable
@@ -251,9 +252,9 @@ object Scanners {
251252
}
252253

253254
/** A migration warning if in Scala-2 mode, an error otherwise */
254-
def errorOrMigrationWarning(msg: String, pos: Position = Position(offset)): Unit =
255-
if (isScala2Mode) ctx.migrationWarning(msg, source.atPos(pos))
256-
else ctx.error(msg, source.atPos(pos))
255+
def errorOrMigrationWarning(msg: String, span: Span = Span(offset)): Unit =
256+
if (isScala2Mode) ctx.migrationWarning(msg, source.atSpan(span))
257+
else ctx.error(msg, source.atSpan(span))
257258

258259
// Get next token ------------------------------------------------------------
259260

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
907907
if (typedArgs.length <= pt.paramInfos.length && !isNamed)
908908
if (typedFn.symbol == defn.Predef_classOf && typedArgs.nonEmpty) {
909909
val arg = typedArgs.head
910-
checkClassType(arg.tpe, arg.posd, traitReq = false, stablePrefixReq = false)
910+
checkClassType(arg.tpe, arg.sourcePos, traitReq = false, stablePrefixReq = false)
911911
}
912912
case _ =>
913913
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ trait Checking {
578578
}
579579

580580
/** Check that type `tp` is stable. */
581-
def checkStable(tp: Type, posd: Positioned)(implicit ctx: Context): Unit =
582-
if (!tp.isStable) ctx.error(ex"$tp is not stable", posd.sourcePos)
581+
def checkStable(tp: Type, pos: SourcePosition)(implicit ctx: Context): Unit =
582+
if (!tp.isStable) ctx.error(ex"$tp is not stable", pos)
583583

584584
/** Check that all type members of `tp` have realizable bounds */
585585
def checkRealizableBounds(cls: Symbol, pos: SourcePosition)(implicit ctx: Context): Unit = {
@@ -594,14 +594,14 @@ trait Checking {
594594
* check that class prefix is stable.
595595
* @return `tp` itself if it is a class or trait ref, ObjectType if not.
596596
*/
597-
def checkClassType(tp: Type, posd: Positioned, traitReq: Boolean, stablePrefixReq: Boolean)(implicit ctx: Context): Type =
597+
def checkClassType(tp: Type, pos: SourcePosition, traitReq: Boolean, stablePrefixReq: Boolean)(implicit ctx: Context): Type =
598598
tp.underlyingClassRef(refinementOK = false) match {
599599
case tref: TypeRef =>
600-
if (traitReq && !(tref.symbol is Trait)) ctx.error(TraitIsExpected(tref.symbol), posd.sourcePos)
601-
if (stablePrefixReq && ctx.phase <= ctx.refchecksPhase) checkStable(tref.prefix, posd)
600+
if (traitReq && !(tref.symbol is Trait)) ctx.error(TraitIsExpected(tref.symbol), pos)
601+
if (stablePrefixReq && ctx.phase <= ctx.refchecksPhase) checkStable(tref.prefix, pos)
602602
tp
603603
case _ =>
604-
ctx.error(ex"$tp is not a class type", posd.sourcePos)
604+
ctx.error(ex"$tp is not a class type", pos)
605605
defn.ObjectType
606606
}
607607

@@ -985,8 +985,8 @@ trait NoChecking extends ReChecking {
985985
override def checkNonCyclic(sym: Symbol, info: TypeBounds, reportErrors: Boolean)(implicit ctx: Context): Type = info
986986
override def checkNonCyclicInherited(joint: Type, parents: List[Type], decls: Scope, posd: Positioned)(implicit ctx: Context): Unit = ()
987987
override def checkValue(tree: Tree, proto: Type)(implicit ctx: Context): tree.type = tree
988-
override def checkStable(tp: Type, posd: Positioned)(implicit ctx: Context): Unit = ()
989-
override def checkClassType(tp: Type, posd: Positioned, traitReq: Boolean, stablePrefixReq: Boolean)(implicit ctx: Context): Type = tp
988+
override def checkStable(tp: Type, pos: SourcePosition)(implicit ctx: Context): Unit = ()
989+
override def checkClassType(tp: Type, pos: SourcePosition, traitReq: Boolean, stablePrefixReq: Boolean)(implicit ctx: Context): Type = tp
990990
override def checkImplicitConversionDefOK(sym: Symbol)(implicit ctx: Context): Unit = ()
991991
override def checkImplicitConversionUseOK(sym: Symbol, posd: Positioned)(implicit ctx: Context): Unit = ()
992992
override def checkFeasibleParent(tp: Type, pos: SourcePosition, where: => String = "")(implicit ctx: Context): Type = tp

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import ast.Trees._
88
import StdNames._
99
import Contexts._, Symbols._, Types._, SymDenotations._, Names._, NameOps._, Flags._, Decorators._
1010
import ProtoTypes._
11-
import util.Positions._
11+
import util.Spans._
12+
import util.SourcePosition
1213
import collection.mutable
1314
import Constants.Constant
1415
import config.Printers.derive
@@ -26,7 +27,7 @@ trait Deriving { this: Typer =>
2627
* synthesized infrastructure code that is not connected with a
2728
* `derives` instance.
2829
*/
29-
class Deriver(cls: ClassSymbol, codePos: Position)(implicit ctx: Context) {
30+
class Deriver(cls: ClassSymbol, codePos: SourcePosition)(implicit ctx: Context) {
3031

3132
/** A buffer for synthesized symbols */
3233
private var synthetics = new mutable.ListBuffer[Symbol]
@@ -114,15 +115,15 @@ trait Deriving { this: Typer =>
114115

115116
/** Create a synthetic symbol owned by current owner */
116117
private def newSymbol(name: Name, info: Type,
117-
pos: Position = ctx.owner.pos,
118+
span: Span = ctx.owner.span,
118119
flags: FlagSet = EmptyFlags)(implicit ctx: Context): Symbol =
119-
ctx.newSymbol(ctx.owner, name, flags | Synthetic, info, coord = pos)
120+
ctx.newSymbol(ctx.owner, name, flags | Synthetic, info, coord = span)
120121

121122
/** Create a synthetic method owned by current owner */
122123
private def newMethod(name: TermName, info: Type,
123-
pos: Position = ctx.owner.pos,
124+
span: Span = ctx.owner.span,
124125
flags: FlagSet = EmptyFlags)(implicit ctx: Context): TermSymbol =
125-
newSymbol(name, info, pos, flags | Method).asTerm
126+
newSymbol(name, info, span, flags | Method).asTerm
126127

127128
/** A version of Type#underlyingClassRef that works also for higher-kinded types */
128129
private def underlyingClassRef(tp: Type): Type = tp match {
@@ -137,12 +138,12 @@ trait Deriving { this: Typer =>
137138
* an instance with the same name does not exist already.
138139
* @param reportErrors Report an error if an instance with the same name exists already
139140
*/
140-
private def addDerivedInstance(clsName: Name, info: Type, pos: Position, reportErrors: Boolean) = {
141+
private def addDerivedInstance(clsName: Name, info: Type, pos: SourcePosition, reportErrors: Boolean) = {
141142
val instanceName = s"derived$$$clsName".toTermName
142143
if (ctx.denotNamed(instanceName).exists) {
143144
if (reportErrors) ctx.error(i"duplicate typeclass derivation for $clsName", pos)
144145
}
145-
else add(newMethod(instanceName, info, pos, Implicit))
146+
else add(newMethod(instanceName, info, pos.span, Implicit))
146147
}
147148

148149
/** Check derived type tree `derived` for the following well-formedness conditions:
@@ -166,7 +167,7 @@ trait Deriving { this: Typer =>
166167
private def processDerivedInstance(derived: untpd.Tree): Unit = {
167168
val originalType = typedAheadType(derived, AnyTypeConstructorProto).tpe
168169
val underlyingType = underlyingClassRef(originalType)
169-
val derivedType = checkClassType(underlyingType, derived.pos, traitReq = false, stablePrefixReq = true)
170+
val derivedType = checkClassType(underlyingType, derived.sourcePos, traitReq = false, stablePrefixReq = true)
170171
val nparams = derivedType.classSymbol.typeParams.length
171172
if (derivedType.isRef(defn.GenericClass))
172173
() // do nothing, a Generic instance will be created anyway by `addGeneric`
@@ -179,20 +180,20 @@ trait Deriving { this: Typer =>
179180
val instanceInfo =
180181
if (cls.typeParams.isEmpty) ExprType(resultType)
181182
else PolyType.fromParams(cls.typeParams, ImplicitMethodType(evidenceParamInfos, resultType))
182-
addDerivedInstance(originalType.typeSymbol.name, instanceInfo, derived.pos, reportErrors = true)
183+
addDerivedInstance(originalType.typeSymbol.name, instanceInfo, derived.sourcePos, reportErrors = true)
183184
}
184185
else
185186
ctx.error(
186187
i"derived class $derivedType should have one type paramater but has $nparams",
187-
derived.pos)
188+
derived.sourcePos)
188189
}
189190

190191
/** Add value corresponding to `val genericClass = new GenericClass(...)`
191192
* to `synthetics`, unless a definition of `genericClass` exists already.
192193
*/
193194
private def addGenericClass(): Unit =
194195
if (!ctx.denotNamed(nme.genericClass).exists) {
195-
add(newSymbol(nme.genericClass, defn.GenericClassType, codePos))
196+
add(newSymbol(nme.genericClass, defn.GenericClassType, codePos.span))
196197
}
197198

198199
private def addGeneric(): Unit = {
@@ -305,7 +306,7 @@ trait Deriving { this: Typer =>
305306
val shape = shapeArg.dealias
306307

307308
val implClassSym = ctx.newNormalizedClassSymbol(
308-
ctx.owner, tpnme.ANON_CLASS, EmptyFlags, genericInstance :: Nil, coord = codePos)
309+
ctx.owner, tpnme.ANON_CLASS, EmptyFlags, genericInstance :: Nil, coord = codePos.span)
309310
val implClassCtx = ctx.withOwner(implClassSym)
310311
val implClassConstr =
311312
newMethod(nme.CONSTRUCTOR, MethodType(Nil, implClassSym.typeRef))(implClassCtx).entered
@@ -330,7 +331,7 @@ trait Deriving { this: Typer =>
330331
case ShapeCases(cases) =>
331332
val clauses = cases.zipWithIndex.map {
332333
case (ShapeCase(pat, elems), idx) =>
333-
val patVar = newSymbol(nme.syntheticParamName(0), pat, meth.pos)
334+
val patVar = newSymbol(nme.syntheticParamName(0), pat, meth.span)
334335
CaseDef(
335336
Bind(patVar, Typed(untpd.Ident(nme.WILDCARD).withType(pat), TypeTree(pat))),
336337
EmptyTree,
@@ -405,7 +406,7 @@ trait Deriving { this: Typer =>
405406
if (typeCls == defn.GenericClass)
406407
genericRHS(resultType, ref(genericClass))
407408
else {
408-
val module = untpd.ref(companionRef).withPos(sym.pos)
409+
val module = untpd.ref(companionRef).withSpan(sym.span)
409410
val rhs = untpd.Select(module, nme.derived)
410411
typed(rhs, resultType)
411412
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,14 +745,15 @@ trait Implicits { self: Typer =>
745745
def synthesizedGeneric(formal: Type): Tree =
746746
formal.argTypes match {
747747
case arg :: Nil =>
748-
val arg1 = fullyDefinedType(arg, "Generic argument", pos)
748+
val pos = ctx.source.atSpan(span)
749+
val arg1 = fullyDefinedType(arg, "Generic argument", span)
749750
val clsType = checkClassType(arg1, pos, traitReq = false, stablePrefixReq = true)
750751
new Deriver(clsType.classSymbol.asClass, pos).genericInstance(clsType)
751752
case _ =>
752753
EmptyTree
753754
}
754755

755-
inferImplicit(formal, EmptyTree, pos)(ctx) match {
756+
inferImplicit(formal, EmptyTree, span)(ctx) match {
756757
case SearchSuccess(arg, _, _) => arg
757758
case fail @ SearchFailure(failed) =>
758759
def trySpecialCase(cls: ClassSymbol, handler: Type => Tree, ifNot: => Tree) = {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -505,14 +505,14 @@ class Namer { typer: Typer =>
505505
* @pre `child` must have a position.
506506
*/
507507
final def addChild(cls: Symbol, child: Symbol)(implicit ctx: Context): Unit = {
508-
val childStart = if (child.pos.exists) child.pos.start else -1
508+
val childStart = if (child.span.exists) child.span.start else -1
509509
def insertInto(annots: List[Annotation]): List[Annotation] =
510510
annots.find(_.symbol == defn.ChildAnnot) match {
511-
case Some(Annotation.Child(other)) if other.pos.exists && childStart <= other.pos.start =>
511+
case Some(Annotation.Child(other)) if other.span.exists && childStart <= other.span.start =>
512512
if (child == other)
513513
annots // can happen if a class has several inaccessible children
514514
else {
515-
assert(childStart != other.pos.start, i"duplicate child annotation $child / $other")
515+
assert(childStart != other.span.start, i"duplicate child annotation $child / $other")
516516
val (prefix, otherAnnot :: rest) = annots.span(_.symbol != defn.ChildAnnot)
517517
prefix ::: otherAnnot :: insertInto(rest)
518518
}
@@ -573,8 +573,8 @@ class Namer { typer: Typer =>
573573
body = fromTempl.body ++ modTempl.body))
574574
if (fromTempl.derived.nonEmpty) {
575575
if (modTempl.derived.nonEmpty)
576-
ctx.error(em"a class and its companion cannot both have `derives' clauses", mdef.pos)
577-
res.putAttachment(desugar.DerivingCompanion, fromTempl.pos.startPos)
576+
ctx.error(em"a class and its companion cannot both have `derives' clauses", mdef.sourcePos)
577+
res.putAttachment(desugar.DerivingCompanion, fromTempl.sourcePos.startPos)
578578
}
579579
res
580580
}
@@ -843,7 +843,7 @@ class Namer { typer: Typer =>
843843
else
844844
ctx.error(em"""children of $cls were already queried before $sym was discovered.
845845
|As a remedy, you could move $sym on the same nesting level as $cls.""",
846-
child.pos)
846+
child.sourcePos)
847847
}
848848
}
849849

@@ -957,7 +957,7 @@ class Namer { typer: Typer =>
957957
val ptype = parentType(parent)(ctx.superCallContext).dealiasKeepAnnots
958958
if (cls.isRefinementClass) ptype
959959
else {
960-
val pt = checkClassType(ptype, parent.posd,
960+
val pt = checkClassType(ptype, parent.sourcePos,
961961
traitReq = parent ne parents.head, stablePrefixReq = true)
962962
if (pt.derivesFrom(cls)) {
963963
val addendum = parent match {
@@ -1014,7 +1014,7 @@ class Namer { typer: Typer =>
10141014
if (impl.derived.nonEmpty) {
10151015
val (derivingClass, derivePos) = original.removeAttachment(desugar.DerivingCompanion) match {
10161016
case Some(pos) => (cls.companionClass.asClass, pos)
1017-
case None => (cls, impl.pos.startPos)
1017+
case None => (cls, impl.sourcePos.startPos)
10181018
}
10191019
val deriver = new Deriver(derivingClass, derivePos)(localCtx)
10201020
deriver.enterDerived(impl.derived)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ class Typer extends Namer
434434
case _ => app
435435
}
436436
case qual1 =>
437-
if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.posd)
437+
if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.sourcePos)
438438
val select = typedSelect(tree, pt, qual1)
439439
if (select.tpe ne TryDynamicCallType) ConstFold(checkStableIdentPattern(select, pt))
440440
else if (pt.isInstanceOf[FunOrPolyProto] || pt == AssignProto) select
@@ -517,7 +517,7 @@ class Typer extends Namer
517517
case TypeApplications.EtaExpansion(tycon) => tpt1 = tpt1.withType(tycon)
518518
case _ =>
519519
}
520-
if (checkClassType(tpt1.tpe, tpt1.posd, traitReq = false, stablePrefixReq = true) eq defn.ObjectType)
520+
if (checkClassType(tpt1.tpe, tpt1.sourcePos, traitReq = false, stablePrefixReq = true) eq defn.ObjectType)
521521
tpt1 = TypeTree(defn.ObjectType).withSpan(tpt1.span)
522522

523523
tpt1 match {
@@ -1242,7 +1242,7 @@ class Typer extends Namer
12421242

12431243
def typedSingletonTypeTree(tree: untpd.SingletonTypeTree)(implicit ctx: Context): SingletonTypeTree = track("typedSingletonTypeTree") {
12441244
val ref1 = typedExpr(tree.ref)
1245-
checkStable(ref1.tpe, tree.posd)
1245+
checkStable(ref1.tpe, tree.sourcePos)
12461246
assignType(cpy.SingletonTypeTree(tree)(ref1), ref1)
12471247
}
12481248

@@ -1748,7 +1748,7 @@ class Typer extends Namer
17481748

17491749
def typedImport(imp: untpd.Import, sym: Symbol)(implicit ctx: Context): Import = track("typedImport") {
17501750
val expr1 = typedExpr(imp.expr, AnySelectionProto)
1751-
checkStable(expr1.tpe, imp.expr.posd)
1751+
checkStable(expr1.tpe, imp.expr.sourcePos)
17521752
if (!ctx.isAfterTyper) checkRealizable(expr1.tpe, imp.expr.posd)
17531753
assignType(cpy.Import(imp)(expr1, imp.selectors), sym)
17541754
}

0 commit comments

Comments
 (0)