Skip to content

Commit 030b726

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 9f1d4b6 commit 030b726

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
@@ -2850,6 +2850,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
28502850

28512851
given PositionMethods: PositionMethods with
28522852
extension (self: Position)
2853+
def exists: Boolean = self.exists
28532854
def start: Int = self.start
28542855
def end: Int = self.end
28552856
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
@@ -4499,6 +4499,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
44994499
/** Extension methods of `Position` */
45004500
trait PositionMethods {
45014501
extension (self: Position)
4502+
/** Whether we have Span information at all */
4503+
def exists: Boolean
45024504

45034505
/** The start offset in the source file */
45044506
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
@@ -266,7 +266,7 @@ trait ClassLikeSupport:
266266
def getParentsAsTreeSymbolTuples: List[(Tree, Symbol)] =
267267
if noPosClassDefs.contains(c.symbol) then Nil
268268
else for
269-
parentTree <- c.parents if parentTree.pos.start != parentTree.pos.end // We assume here that order is correct
269+
parentTree <- c.parents if parentTree.pos.exists && parentTree.pos.start != parentTree.pos.end // We assume here that order is correct
270270
parentSymbol = parentTree match
271271
case t: TypeTree => t.tpe.typeSymbol
272272
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
@@ -106,3 +106,5 @@ class ImplicitMembers extends SignatureTest(
106106
Seq("def"),
107107
filterFunc = _.toString.endsWith("OuterClass$ImplicitMemberTarget.html")
108108
)
109+
110+
class NonScala3Parent extends SignatureTest("nonScala3Parent", SignatureTest.all)

0 commit comments

Comments
 (0)