Skip to content

Commit ea906aa

Browse files
committed
Extend the PositionMethods with an exists method, since the other methods are not safe to call on non-existing Spans.
Fixes scala#15927
1 parent 72c4ffd commit ea906aa

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,6 +2813,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
28132813

28142814
given PositionMethods: PositionMethods with
28152815
extension (self: Position)
2816+
def exists: Boolean = self.exists
28162817
def start: Int = self.start
28172818
def end: Int = self.end
28182819
def sourceFile: SourceFile = self.source

library/src/scala/quoted/Quotes.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4399,6 +4399,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
43994399
/** Extension methods of `Position` */
44004400
trait PositionMethods {
44014401
extension (self: Position)
4402+
/** Whether we have Span information at all */
4403+
def exists: Boolean
44024404

44034405
/** The start offset in the source file */
44044406
def start: Int
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tests
2+
package nonScala3Parent
3+
4+
import javax.swing.JPanel
5+
import javax.swing.JFrame
6+
7+
// https://github.com/lampepfl/dotty/issues/15927
8+
9+
trait Foo1 extends Numeric[Any]
10+
trait Foo2 extends JPanel
11+
trait Foo3 extends JFrame
12+
trait Foo4 extends Ordering[Any]
13+
trait Foo5 extends Enumeration

scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ trait ClassLikeSupport:
265265
def getParentsAsTreeSymbolTuples: List[(Tree, Symbol)] =
266266
if noPosClassDefs.contains(c.symbol) then Nil
267267
else for
268-
parentTree <- c.parents if parentTree.pos.start != parentTree.pos.end // We assume here that order is correct
268+
parentTree <- c.parents if parentTree.pos.exists && parentTree.pos.start != parentTree.pos.end // We assume here that order is correct
269269
parentSymbol = parentTree match
270270
case t: TypeTree => t.tpe.typeSymbol
271271
case tree if tree.symbol.isClassConstructor => tree.symbol.owner

scaladoc/test/dotty/tools/scaladoc/signatures/TranslatableSignaturesTestCases.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ class ImplicitMembers extends SignatureTest(
104104
Seq("def"),
105105
filterFunc = _.toString.endsWith("OuterClass$ImplicitMemberTarget.html")
106106
)
107+
108+
class NonScala3Parent extends SignatureTest("nonScala3Parent", SignatureTest.all)

0 commit comments

Comments
 (0)