@@ -327,42 +327,45 @@ object Trees {
327
327
328
328
extension (mdef : untpd.DefTree ) def mods : untpd.Modifiers = mdef.rawMods
329
329
330
- /** PackageDef | NamedDefTree */
331
- sealed trait WithEndMarker :
332
- self : Attachment .Container =>
330
+ sealed trait WithEndMarker [- T >: Untyped ]:
331
+ self : PackageDef [T ] | NamedDefTree [T ] =>
333
332
334
333
import WithEndMarker .*
335
334
336
335
final def endSpan (using Context ): Span =
337
- self.getAttachment( EndIndex ) match
338
- case Some (end) =>
339
- val realName = srcName.stripModuleClassSuffix.lastPart
340
- Span (end - realName.length, end)
341
- case none => NoSpan
336
+ if hasEnd then
337
+ val realName = srcName.stripModuleClassSuffix.lastPart
338
+ span.withStart(span.end - realName.length)
339
+ else
340
+ NoSpan
342
341
343
342
protected def srcName (using Context ): Name
344
343
345
- final def withEndIndex (index : Int ): self.type =
346
- self.withAttachment(EndIndex , index )
344
+ final def withEndIndex (): self.type =
345
+ self.withAttachment(EndIndex , () )
347
346
348
- final def withEndIndex (copyFrom : WithEndMarker ): self.type =
349
- copyFrom.endIndex.foreach(withEndIndex)
350
- this
347
+ final def withEndIndex (copyFrom : WithEndMarker [T @ uncheckedVariance]): self.type =
348
+ if copyFrom.hasEnd then
349
+ this .withEndIndex()
350
+ else
351
+ this
351
352
352
353
final def dropEndIndex (): self.type =
353
354
self.removeAttachment(EndIndex )
354
355
this
355
356
356
- protected def endIndex : Option [ Int ] = self.getAttachment (EndIndex )
357
+ protected def hasEnd : Boolean = self.hasAttachment (EndIndex )
357
358
358
359
object WithEndMarker :
359
- /** Property key for trees with an `end` marker */
360
- private val EndIndex : Property .StickyKey [Int ] = Property .StickyKey ()
360
+ /** Property key that signals the tree was terminated
361
+ * with an `end` marker in the source code
362
+ */
363
+ private val EndIndex : Property .StickyKey [Unit ] = Property .StickyKey ()
361
364
362
365
end WithEndMarker
363
366
364
367
abstract class NamedDefTree [- T >: Untyped ](implicit @ constructorOnly src : SourceFile )
365
- extends NameTree [T ] with DefTree [T ] with WithEndMarker {
368
+ extends NameTree [T ] with DefTree [T ] with WithEndMarker [ T ] {
366
369
type ThisTree [- T >: Untyped ] <: NamedDefTree [T ]
367
370
368
371
protected def srcName (using Context ): Name =
@@ -897,7 +900,7 @@ object Trees {
897
900
898
901
/** package pid { stats } */
899
902
case class PackageDef [- T >: Untyped ] private [ast] (pid : RefTree [T ], stats : List [Tree [T ]])(implicit @ constructorOnly src : SourceFile )
900
- extends ProxyTree [T ] with WithEndMarker {
903
+ extends ProxyTree [T ] with WithEndMarker [ T ] {
901
904
type ThisTree [- T >: Untyped ] = PackageDef [T ]
902
905
def forwardTo : RefTree [T ] = pid
903
906
protected def srcName (using Context ): Name = pid.name
@@ -1092,6 +1095,8 @@ object Trees {
1092
1095
type Annotated = Trees .Annotated [T ]
1093
1096
type Thicket = Trees .Thicket [T ]
1094
1097
1098
+ type WithEndMarker = Trees .WithEndMarker [T ]
1099
+
1095
1100
@ sharable val EmptyTree : Thicket = genericEmptyTree
1096
1101
@ sharable val EmptyValDef : ValDef = genericEmptyValDef
1097
1102
@ sharable val ContextualEmptyTree : Thicket = new EmptyTree () // an empty tree marking a contextual closure
0 commit comments