Skip to content

Commit 65187a3

Browse files
committed
escape ctor in srcName
1 parent 3ebfd4a commit 65187a3

File tree

6 files changed

+14
-17
lines changed

6 files changed

+14
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ object desugar {
875875
val modul = ValDef(moduleName, clsRef, New(clsRef, Nil))
876876
.withMods(mods.toTermFlags & RetainedModuleValFlags | ModuleValCreationFlags)
877877
.withSpan(mdef.span.startPos)
878-
.withEndIndex(copyFrom = mdef) // copy over the end market position to the module val
878+
.withEndIndex(copyFrom = mdef) // copy over the end marker position to the module val
879879
val ValDef(selfName, selfTpt, _) = impl.self
880880
val selfMods = impl.self.mods
881881
if (!selfTpt.isEmpty) report.error(ObjectMayNotHaveSelfType(mdef), impl.self.srcPos)

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ object Trees {
336336
final def endSpan(using Context): Span =
337337
self.getAttachment(EndIndex) match
338338
case Some(end) =>
339-
val realName = endName.stripModuleClassSuffix.lastPart
339+
val realName = srcName.stripModuleClassSuffix.lastPart
340340
Span(end - realName.length, end)
341341
case none => NoSpan
342342

343-
protected def endName(using Context): Name
343+
protected def srcName(using Context): Name
344344

345345
final def withEndIndex(index: Int): self.type =
346346
self.withAttachment(EndIndex, index)
@@ -365,12 +365,9 @@ object Trees {
365365
extends NameTree[T] with DefTree[T] with WithEndMarker {
366366
type ThisTree[-T >: Untyped] <: NamedDefTree[T]
367367

368-
protected def endName(using Context) =
369-
if name == nme.CONSTRUCTOR then nme.this_
370-
else srcName
371-
372368
protected def srcName(using Context): Name =
373-
if symbol.isPackageObject then symbol.owner.name
369+
if name == nme.CONSTRUCTOR then nme.this_
370+
else if symbol.isPackageObject then symbol.owner.name
374371
else name
375372

376373
/** The position of the name defined by this definition.
@@ -903,7 +900,7 @@ object Trees {
903900
extends ProxyTree[T] with WithEndMarker {
904901
type ThisTree[-T >: Untyped] = PackageDef[T]
905902
def forwardTo: RefTree[T] = pid
906-
protected def endName(using Context): Name = pid.name
903+
protected def srcName(using Context): Name = pid.name
907904
}
908905

909906
/** arg @annot */

tests/semanticdb/expect/Annotations.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Annotations/*<-annot::Annotations#*/[@TypeParameterAnnotation/*->com::java
2121

2222
class B/*<-annot::B#*/ @ConstructorAnnotation/*->com::javacp::annot::ConstructorAnnotation#*/()(x/*<-annot::B#x.*/: Int/*->scala::Int#*/) {
2323
@ConstructorAnnotation/*->com::javacp::annot::ConstructorAnnotation#*/
24-
def this()/*<-annot::B#`<init>`(+1).*/ = this(42)
24+
def this/*<-annot::B#`<init>`(+1).*/() = this(42)
2525
}
2626

2727
@ObjectAnnotation/*->com::javacp::annot::ObjectAnnotation#*/

tests/semanticdb/expect/EndMarkers.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package endmarkers:
22

33
class MultiCtor/*<-endmarkers::MultiCtor#*/(val i/*<-endmarkers::MultiCtor#i.*/: Int/*->scala::Int#*/):
4-
def this()/*<-endmarkers::MultiCtor#`<init>`(+1).*/ =
4+
def this/*<-endmarkers::MultiCtor#`<init>`(+1).*/() =
55
this(23)
66
end this/*->endmarkers::MultiCtor#`<init>`(+1).*/
77
end MultiCtor/*->endmarkers::MultiCtor#*/

tests/semanticdb/expect/semanticdb-Flags.expect.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ package object p/*<-flags::p::package.*/ {
88
def z/*<-flags::p::package.z().*/(pp/*<-flags::p::package.z().(pp)*/: Int/*->scala::Int#*/) = 3
99
def m/*<-flags::p::package.m().*/[TT/*<-flags::p::package.m().[TT]*/]: Int/*->scala::Int#*/ = macro ???/*->scala::Predef.`???`().*/
1010
abstract class C/*<-flags::p::package.C#*/[+T/*<-flags::p::package.C#[T]*/, -U/*<-flags::p::package.C#[U]*/, V/*<-flags::p::package.C#[V]*/](x/*<-flags::p::package.C#x.*/: T/*->flags::p::package.C#[T]*/, y/*<-flags::p::package.C#y.*/: U/*->flags::p::package.C#[U]*/, z/*<-flags::p::package.C#z.*/: V/*->flags::p::package.C#[V]*/) {
11-
def this()/*<-flags::p::package.C#`<init>`(+1).*/ = this(???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/)
12-
def this(t/*<-flags::p::package.C#`<init>`(+2).*//*<-flags::p::package.C#`<init>`(+2).(t)*/: T/*->flags::p::package.C#[T]*/) = this(t/*->flags::p::package.C#`<init>`(+2).(t)*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/)
11+
def this/*<-flags::p::package.C#`<init>`(+1).*/() = this(???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/)
12+
def this/*<-flags::p::package.C#`<init>`(+2).*/(t/*<-flags::p::package.C#`<init>`(+2).(t)*/: T/*->flags::p::package.C#[T]*/) = this(t/*->flags::p::package.C#`<init>`(+2).(t)*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/)
1313
def w/*<-flags::p::package.C#w().*/: Int/*->scala::Int#*/
1414
}
1515
type T1/*<-flags::p::package.T1#*/ = Int/*->scala::Int#*/

tests/semanticdb/metac.expect

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Occurrences:
252252
[21:33..21:34): x <- annot/B#x.
253253
[21:36..21:39): Int -> scala/Int#
254254
[22:3..22:24): ConstructorAnnotation -> com/javacp/annot/ConstructorAnnotation#
255-
[23:6..23:12): <- annot/B#`<init>`(+1).
255+
[23:6..23:10): <- annot/B#`<init>`(+1).
256256
[23:20..23:20): -> annot/B#`<init>`().
257257
[26:1..26:17): ObjectAnnotation -> com/javacp/annot/ObjectAnnotation#
258258
[27:7..27:8): M <- annot/M.
@@ -701,7 +701,7 @@ Occurrences:
701701
[2:17..2:17): <- endmarkers/MultiCtor#`<init>`().
702702
[2:22..2:23): i <- endmarkers/MultiCtor#i.
703703
[2:25..2:28): Int -> scala/Int#
704-
[3:8..3:14): <- endmarkers/MultiCtor#`<init>`(+1).
704+
[3:8..3:12): <- endmarkers/MultiCtor#`<init>`(+1).
705705
[4:11..4:11): -> endmarkers/MultiCtor#`<init>`().
706706
[5:8..5:12): this -> endmarkers/MultiCtor#`<init>`(+1).
707707
[6:6..6:15): MultiCtor -> endmarkers/MultiCtor#
@@ -3856,12 +3856,12 @@ Occurrences:
38563856
[9:39..9:40): U -> flags/p/package.C#[U]
38573857
[9:42..9:43): z <- flags/p/package.C#z.
38583858
[9:45..9:46): V -> flags/p/package.C#[V]
3859-
[10:8..10:14): <- flags/p/package.C#`<init>`(+1).
3859+
[10:8..10:12): <- flags/p/package.C#`<init>`(+1).
38603860
[10:22..10:22): -> flags/p/package.C#`<init>`().
38613861
[10:22..10:25): ??? -> scala/Predef.`???`().
38623862
[10:27..10:30): ??? -> scala/Predef.`???`().
38633863
[10:32..10:35): ??? -> scala/Predef.`???`().
3864-
[11:8..11:14): <- flags/p/package.C#`<init>`(+2).
3864+
[11:8..11:12): <- flags/p/package.C#`<init>`(+2).
38653865
[11:13..11:14): t <- flags/p/package.C#`<init>`(+2).(t)
38663866
[11:16..11:17): T -> flags/p/package.C#[T]
38673867
[11:26..11:26): -> flags/p/package.C#`<init>`().

0 commit comments

Comments
 (0)