Skip to content

Commit ba24fe1

Browse files
committed
Add test file for semanticdb and ignore symbol lookup failures
```scala val a: String = (((1: Any): b.A): Nothing): String val b: { type A >: Any <: Nothing } = loop() ``` We can't resolve a symbol of `b.A` in `(1: Any): b.A` because semanticdb generator basically resolves the symbol of refinement members (like `type A` of `b`) by - Traverse trees and collect symbol information by **depth-first** way - during the traversal, we register the symbols of refinement members to a symbol table. - Then outer part of program can resolve the symbol of refinements by looking up symbols from the symbol table. However, in this case, we failed to resolve the symbol of b.A bacause - (1) We try to lookup the symbol of `b.A` first, which has not yet registered to the symtab. - (2) And then register a symbol for A in b by traversing `b`. Maybe we could fix this issue by - (a) Generate fake symbol for `b.A` in (1), and register it to the symtab - (b) in (2), when we register the "real" symbol of `A`, it should collide with the symbol registered in step (a) - (c) if they had collision, we mark those symbols (fake one and real one) as an alias - (d) on building the semanticdb symbol, we use the same symbol for both fake one and real one
1 parent 8465366 commit ba24fe1

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

compiler/src/dotty/tools/dotc/semanticdb/TypeOps.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class TypeOps:
7979
case OrType(tp1, tp2) =>
8080
loop(tp1).orElse(loop(tp2))
8181
case _ =>
82-
symbolNotFound(name, tpe.typeSymbol)
8382
None
8483
loop(tpe.dealias)
8584
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package i5854
2+
3+
class B/*<-i5854::B#*/ {
4+
// Known issue: Can't lookup the symbol of `b.A`
5+
// we have to register the symbol of `b { type A }` to the refinementSymtab first
6+
// then resolve, or assign same semanticdb symbol for both
7+
// fake symbol for b.A, and real symbol of A in b
8+
val a/*<-i5854::B#a.*/: String/*->scala::Predef.String#*/ = (((1: Any/*->scala::Any#*/): b/*->i5854::B#b.*/.A): Nothing/*->scala::Nothing#*/): String/*->scala::Predef.String#*/
9+
val b/*<-i5854::B#b.*/: { type A/*<-local0*/ >: Any/*->scala::Any#*/ <: Nothing/*->scala::Nothing#*/ } = loop/*->i5854::B#loop().*/() // error
10+
def loop/*<-i5854::B#loop().*/(): Nothing/*->scala::Nothing#*/ = loop/*->i5854::B#loop().*/()
11+
}

tests/semanticdb/expect/i5854.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package i5854
2+
3+
class B {
4+
// Known issue: Can't lookup the symbol of `b.A`
5+
// we have to register the symbol of `b { type A }` to the refinementSymtab first
6+
// then resolve, or assign same semanticdb symbol for both
7+
// fake symbol for b.A, and real symbol of A in b
8+
val a: String = (((1: Any): b.A): Nothing): String
9+
val b: { type A >: Any <: Nothing } = loop() // error
10+
def loop(): Nothing = loop()
11+
}

tests/semanticdb/metac.expect

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3880,6 +3880,43 @@ Occurrences:
38803880
[0:8..0:15): example <- example/
38813881
[2:6..2:24): FilenameWithSpaces <- example/FilenameWithSpaces#
38823882

3883+
expect/i5854.scala
3884+
------------------
3885+
3886+
Summary:
3887+
Schema => SemanticDB v4
3888+
Uri => i5854.scala
3889+
Text => empty
3890+
Language => Scala
3891+
Symbols => 6 entries
3892+
Occurrences => 16 entries
3893+
3894+
Symbols:
3895+
i5854/B# => class B extends Object { self: B => +4 decls }
3896+
i5854/B#`<init>`(). => primary ctor <init> (): B
3897+
i5854/B#a. => val method a String
3898+
i5854/B#b. => val method b Object { type A >: Any <: Nothing }
3899+
i5854/B#loop(). => method loop (): Nothing
3900+
local0 => type A >: Any <: Nothing
3901+
3902+
Occurrences:
3903+
[0:8..0:13): i5854 <- i5854/
3904+
[2:6..2:7): B <- i5854/B#
3905+
[7:6..7:7): a <- i5854/B#a.
3906+
[7:9..7:15): String -> scala/Predef.String#
3907+
[7:24..7:27): Any -> scala/Any#
3908+
[7:30..7:31): b -> i5854/B#b.
3909+
[7:36..7:43): Nothing -> scala/Nothing#
3910+
[7:46..7:52): String -> scala/Predef.String#
3911+
[8:6..8:7): b <- i5854/B#b.
3912+
[8:16..8:17): A <- local0
3913+
[8:21..8:24): Any -> scala/Any#
3914+
[8:28..8:35): Nothing -> scala/Nothing#
3915+
[8:40..8:44): loop -> i5854/B#loop().
3916+
[9:6..9:10): loop <- i5854/B#loop().
3917+
[9:14..9:21): Nothing -> scala/Nothing#
3918+
[9:24..9:28): loop -> i5854/B#loop().
3919+
38833920
expect/i9727.scala
38843921
------------------
38853922

0 commit comments

Comments
 (0)