Skip to content

Commit a1e0f7f

Browse files
committed
Dealias LazyRef while converting types to SemanticDB
1 parent 2b651c3 commit a1e0f7f

File tree

6 files changed

+229
-0
lines changed

6 files changed

+229
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ class TypeOps:
364364
val stpes = flatten(or).map(loop)
365365
s.UnionType(stpes)
366366

367+
case l: LazyRef =>
368+
loop(l.ref)
369+
367370
case NoPrefix =>
368371
s.Type.Empty
369372

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// LazyRef
2+
trait Txn/*<-_empty_::Txn#*/[T/*<-_empty_::Txn#[T]*/ <: Txn[T]]
3+
4+
trait Elem/*<-_empty_::Elem#*/[T/*<-_empty_::Elem#[T]*/ <: Txn[T]]
5+
6+
trait Obj/*<-_empty_::Obj#*/[T/*<-_empty_::Obj#[T]*/ <: Txn[T]] extends Elem/*->_empty_::Elem#*/[T/*->_empty_::Obj#[T]*/]
7+
8+
trait Copy/*<-_empty_::Copy#*/[In/*<-_empty_::Copy#[In]*/ <: Txn[In], Out/*<-_empty_::Copy#[Out]*/ <: Txn[Out]] {
9+
def copyImpl/*<-_empty_::Copy#copyImpl().*/[Repr/*<-_empty_::Copy#copyImpl().[Repr]*/[~ <: Txn[~]] <: Elem[~]](in/*<-_empty_::Copy#copyImpl().(in)*/: Repr/*->_empty_::Copy#copyImpl().[Repr]*/[In/*->_empty_::Copy#[In]*/]): Repr/*->_empty_::Copy#copyImpl().[Repr]*/[Out/*->_empty_::Copy#[Out]*/]
10+
11+
def apply/*<-_empty_::Copy#apply().*/[Repr/*<-_empty_::Copy#apply().[Repr]*/[~ <: Txn[~]] <: Elem[~]](in/*<-_empty_::Copy#apply().(in)*/: Repr/*->_empty_::Copy#apply().[Repr]*/[In/*->_empty_::Copy#[In]*/]): Repr/*->_empty_::Copy#apply().[Repr]*/[Out/*->_empty_::Copy#[Out]*/] = {
12+
val out/*<-local0*/ = copyImpl/*->_empty_::Copy#copyImpl().*/[Repr/*->_empty_::Copy#apply().[Repr]*/](in/*->_empty_::Copy#apply().(in)*/)
13+
(/*->scala::Tuple2.apply().*/in/*->_empty_::Copy#apply().(in)*/, out/*->local0*/) match {
14+
case (/*->scala::Tuple2.unapply().*/inObj/*<-local1*/: Obj/*->_empty_::Obj#*/[In/*->_empty_::Copy#[In]*/], outObj/*<-local2*/: Obj/*->_empty_::Obj#*/[Out/*->_empty_::Copy#[Out]*/]) => // problem here
15+
println/*->scala::Predef.println(+1).*/("copy the attributes")
16+
case _ =>
17+
}
18+
out/*->local0*/
19+
}
20+
}

tests/semanticdb/expect/i9782.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// LazyRef
2+
trait Txn[T <: Txn[T]]
3+
4+
trait Elem[T <: Txn[T]]
5+
6+
trait Obj[T <: Txn[T]] extends Elem[T]
7+
8+
trait Copy[In <: Txn[In], Out <: Txn[Out]] {
9+
def copyImpl[Repr[~ <: Txn[~]] <: Elem[~]](in: Repr[In]): Repr[Out]
10+
11+
def apply[Repr[~ <: Txn[~]] <: Elem[~]](in: Repr[In]): Repr[Out] = {
12+
val out = copyImpl[Repr](in)
13+
(in, out) match {
14+
case (inObj: Obj[In], outObj: Obj[Out]) => // problem here
15+
println("copy the attributes")
16+
case _ =>
17+
}
18+
out
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
abstract class NullaryTest/*<-_empty_::NullaryTest#*/[T/*<-_empty_::NullaryTest#[T]*/, m/*<-_empty_::NullaryTest#[m]*/[s]] {
2+
def nullary/*<-_empty_::NullaryTest#nullary().*/: String/*->scala::Predef.String#*/ = "a"
3+
val x/*<-_empty_::NullaryTest#x.*/ = nullary/*->_empty_::NullaryTest#nullary().*/
4+
5+
def nullary2/*<-_empty_::NullaryTest#nullary2().*/: T/*->_empty_::NullaryTest#[T]*/
6+
val x2/*<-_empty_::NullaryTest#x2.*/ = nullary2/*->_empty_::NullaryTest#nullary2().*/
7+
8+
def nullary3/*<-_empty_::NullaryTest#nullary3().*/: m/*->_empty_::NullaryTest#[m]*/[T/*->_empty_::NullaryTest#[T]*/]
9+
val x3/*<-_empty_::NullaryTest#x3.*/ = nullary3/*->_empty_::NullaryTest#nullary3().*/
10+
}
11+
12+
class Concrete/*<-_empty_::Concrete#*/ extends NullaryTest/*->_empty_::NullaryTest#*/[Int/*->scala::Int#*/, List/*->scala::package.List#*/] {
13+
def nullary2/*<-_empty_::Concrete#nullary2().*/ = 1
14+
def nullary3/*<-_empty_::Concrete#nullary3().*/ = List/*->scala::package.List.*//*->scala::collection::IterableFactory#apply().*/(1,2,3)
15+
}
16+
17+
object test/*<-_empty_::test.*/ {
18+
(new Concrete/*->_empty_::Concrete#*/).nullary2/*->_empty_::Concrete#nullary2().*/
19+
(new Concrete/*->_empty_::Concrete#*/).nullary3/*->_empty_::Concrete#nullary3().*/
20+
}

tests/semanticdb/expect/nullary.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
abstract class NullaryTest[T, m[s]] {
2+
def nullary: String = "a"
3+
val x = nullary
4+
5+
def nullary2: T
6+
val x2 = nullary2
7+
8+
def nullary3: m[T]
9+
val x3 = nullary3
10+
}
11+
12+
class Concrete extends NullaryTest[Int, List] {
13+
def nullary2 = 1
14+
def nullary3 = List(1,2,3)
15+
}
16+
17+
object test {
18+
(new Concrete).nullary2
19+
(new Concrete).nullary3
20+
}

tests/semanticdb/metac.expect

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,6 +3846,88 @@ Occurrences:
38463846
[4:12..4:16): Test -> i9727/Test#
38473847
[4:16..4:16): -> i9727/Test#`<init>`().
38483848

3849+
expect/i9782.scala
3850+
------------------
3851+
3852+
Summary:
3853+
Schema => SemanticDB v4
3854+
Uri => i9782.scala
3855+
Text => empty
3856+
Language => Scala
3857+
Symbols => 22 entries
3858+
Occurrences => 45 entries
3859+
3860+
Symbols:
3861+
_empty_/Copy# => trait Copy [typeparam In <: Txn[In], typeparam Out <: Txn[Out]] extends Object { self: Copy[In, Out] => +5 decls }
3862+
_empty_/Copy#[In] => typeparam In <: Txn[In]
3863+
_empty_/Copy#[Out] => typeparam Out <: Txn[Out]
3864+
_empty_/Copy#`<init>`(). => primary ctor <init> [typeparam In <: Txn[In], typeparam Out <: Txn[Out]](): Copy[In, Out]
3865+
_empty_/Copy#apply(). => method apply [typeparam Repr [unknown ~: <?>] <: Elem[~]](param in: Repr[In]): Repr[Out]
3866+
_empty_/Copy#apply().(in) => param in: Repr[In]
3867+
_empty_/Copy#apply().[Repr] => typeparam Repr [unknown ~: <?>] <: Elem[~]
3868+
_empty_/Copy#copyImpl(). => abstract method copyImpl [typeparam Repr [unknown ~: <?>] <: Elem[~]](param in: Repr[In]): Repr[Out]
3869+
_empty_/Copy#copyImpl().(in) => param in: Repr[In]
3870+
_empty_/Copy#copyImpl().[Repr] => typeparam Repr [unknown ~: <?>] <: Elem[~]
3871+
_empty_/Elem# => trait Elem [typeparam T <: Txn[T]] extends Object { self: Elem[T] => +2 decls }
3872+
_empty_/Elem#[T] => typeparam T <: Txn[T]
3873+
_empty_/Elem#`<init>`(). => primary ctor <init> [typeparam T <: Txn[T]](): Elem[T]
3874+
_empty_/Obj# => trait Obj [typeparam T <: Txn[T]] extends Object with Elem[T] { self: Obj[T] => +2 decls }
3875+
_empty_/Obj#[T] => typeparam T <: Txn[T]
3876+
_empty_/Obj#`<init>`(). => primary ctor <init> [typeparam T <: Txn[T]](): Obj[T]
3877+
_empty_/Txn# => trait Txn [typeparam T <: Txn[T]] extends Object { self: Txn[T] => +2 decls }
3878+
_empty_/Txn#[T] => typeparam T <: Txn[T]
3879+
_empty_/Txn#`<init>`(). => primary ctor <init> [typeparam T <: Txn[T]](): Txn[T]
3880+
local0 => val local out: Repr[Out]
3881+
local1 => val local inObj: Repr[In] & Obj[In]
3882+
local2 => val local outObj: Repr[Out] & Obj[Out]
3883+
3884+
Occurrences:
3885+
[1:6..1:9): Txn <- _empty_/Txn#
3886+
[1:9..1:9): <- _empty_/Txn#`<init>`().
3887+
[1:10..1:11): T <- _empty_/Txn#[T]
3888+
[3:6..3:10): Elem <- _empty_/Elem#
3889+
[3:10..3:10): <- _empty_/Elem#`<init>`().
3890+
[3:11..3:12): T <- _empty_/Elem#[T]
3891+
[5:6..5:9): Obj <- _empty_/Obj#
3892+
[5:9..5:9): <- _empty_/Obj#`<init>`().
3893+
[5:10..5:11): T <- _empty_/Obj#[T]
3894+
[5:31..5:35): Elem -> _empty_/Elem#
3895+
[5:36..5:37): T -> _empty_/Obj#[T]
3896+
[7:6..7:10): Copy <- _empty_/Copy#
3897+
[7:10..7:10): <- _empty_/Copy#`<init>`().
3898+
[7:11..7:13): In <- _empty_/Copy#[In]
3899+
[7:26..7:29): Out <- _empty_/Copy#[Out]
3900+
[8:6..8:14): copyImpl <- _empty_/Copy#copyImpl().
3901+
[8:15..8:19): Repr <- _empty_/Copy#copyImpl().[Repr]
3902+
[8:45..8:47): in <- _empty_/Copy#copyImpl().(in)
3903+
[8:49..8:53): Repr -> _empty_/Copy#copyImpl().[Repr]
3904+
[8:54..8:56): In -> _empty_/Copy#[In]
3905+
[8:60..8:64): Repr -> _empty_/Copy#copyImpl().[Repr]
3906+
[8:65..8:68): Out -> _empty_/Copy#[Out]
3907+
[10:6..10:11): apply <- _empty_/Copy#apply().
3908+
[10:12..10:16): Repr <- _empty_/Copy#apply().[Repr]
3909+
[10:42..10:44): in <- _empty_/Copy#apply().(in)
3910+
[10:46..10:50): Repr -> _empty_/Copy#apply().[Repr]
3911+
[10:51..10:53): In -> _empty_/Copy#[In]
3912+
[10:57..10:61): Repr -> _empty_/Copy#apply().[Repr]
3913+
[10:62..10:65): Out -> _empty_/Copy#[Out]
3914+
[11:8..11:11): out <- local0
3915+
[11:14..11:22): copyImpl -> _empty_/Copy#copyImpl().
3916+
[11:23..11:27): Repr -> _empty_/Copy#apply().[Repr]
3917+
[11:29..11:31): in -> _empty_/Copy#apply().(in)
3918+
[12:5..12:5): -> scala/Tuple2.apply().
3919+
[12:5..12:7): in -> _empty_/Copy#apply().(in)
3920+
[12:9..12:12): out -> local0
3921+
[13:12..13:12): -> scala/Tuple2.unapply().
3922+
[13:12..13:17): inObj <- local1
3923+
[13:19..13:22): Obj -> _empty_/Obj#
3924+
[13:23..13:25): In -> _empty_/Copy#[In]
3925+
[13:28..13:34): outObj <- local2
3926+
[13:36..13:39): Obj -> _empty_/Obj#
3927+
[13:40..13:43): Out -> _empty_/Copy#[Out]
3928+
[14:8..14:15): println -> scala/Predef.println(+1).
3929+
[17:4..17:7): out -> local0
3930+
38493931
expect/inlineconsume.scala
38503932
--------------------------
38513933

@@ -3928,6 +4010,70 @@ Occurrences:
39284010
[5:4..5:9): local -> local0
39294011
[5:10..5:11): + -> scala/Int#`+`(+4).
39304012

4013+
expect/nullary.scala
4014+
--------------------
4015+
4016+
Summary:
4017+
Schema => SemanticDB v4
4018+
Uri => nullary.scala
4019+
Text => empty
4020+
Language => Scala
4021+
Symbols => 15 entries
4022+
Occurrences => 34 entries
4023+
4024+
Symbols:
4025+
_empty_/Concrete# => class Concrete extends NullaryTest[Int, List] { self: Concrete => +3 decls }
4026+
_empty_/Concrete#`<init>`(). => primary ctor <init> (): Concrete
4027+
_empty_/Concrete#nullary2(). => method nullary2 => Int
4028+
_empty_/Concrete#nullary3(). => method nullary3 => List[Int]
4029+
_empty_/NullaryTest# => abstract class NullaryTest [typeparam T , typeparam m [unknown s: <?>]] extends Object { self: NullaryTest[T, m] => +9 decls }
4030+
_empty_/NullaryTest#[T] => typeparam T
4031+
_empty_/NullaryTest#[m] => typeparam m [unknown s: <?>]
4032+
_empty_/NullaryTest#`<init>`(). => primary ctor <init> [typeparam T , typeparam m [unknown s: <?>]](): NullaryTest[T, m]
4033+
_empty_/NullaryTest#nullary(). => method nullary => String
4034+
_empty_/NullaryTest#nullary2(). => abstract method nullary2 => T
4035+
_empty_/NullaryTest#nullary3(). => abstract method nullary3 => m[T]
4036+
_empty_/NullaryTest#x. => val method x String
4037+
_empty_/NullaryTest#x2. => val method x2 T
4038+
_empty_/NullaryTest#x3. => val method x3 m[T]
4039+
_empty_/test. => final object test extends Object { self: test.type => +1 decls }
4040+
4041+
Occurrences:
4042+
[0:15..0:26): NullaryTest <- _empty_/NullaryTest#
4043+
[0:26..0:26): <- _empty_/NullaryTest#`<init>`().
4044+
[0:27..0:28): T <- _empty_/NullaryTest#[T]
4045+
[0:30..0:31): m <- _empty_/NullaryTest#[m]
4046+
[1:6..1:13): nullary <- _empty_/NullaryTest#nullary().
4047+
[1:15..1:21): String -> scala/Predef.String#
4048+
[2:6..2:7): x <- _empty_/NullaryTest#x.
4049+
[2:10..2:17): nullary -> _empty_/NullaryTest#nullary().
4050+
[4:6..4:14): nullary2 <- _empty_/NullaryTest#nullary2().
4051+
[4:16..4:17): T -> _empty_/NullaryTest#[T]
4052+
[5:6..5:8): x2 <- _empty_/NullaryTest#x2.
4053+
[5:11..5:19): nullary2 -> _empty_/NullaryTest#nullary2().
4054+
[7:6..7:14): nullary3 <- _empty_/NullaryTest#nullary3().
4055+
[7:16..7:17): m -> _empty_/NullaryTest#[m]
4056+
[7:18..7:19): T -> _empty_/NullaryTest#[T]
4057+
[8:6..8:8): x3 <- _empty_/NullaryTest#x3.
4058+
[8:11..8:19): nullary3 -> _empty_/NullaryTest#nullary3().
4059+
[11:6..11:14): Concrete <- _empty_/Concrete#
4060+
[11:23..11:34): NullaryTest -> _empty_/NullaryTest#
4061+
[11:23..11:23): <- _empty_/Concrete#`<init>`().
4062+
[11:35..11:38): Int -> scala/Int#
4063+
[11:40..11:44): List -> scala/package.List#
4064+
[11:45..11:45): -> _empty_/NullaryTest#`<init>`().
4065+
[12:6..12:14): nullary2 <- _empty_/Concrete#nullary2().
4066+
[13:6..13:14): nullary3 <- _empty_/Concrete#nullary3().
4067+
[13:17..13:21): List -> scala/package.List.
4068+
[13:21..13:21): -> scala/collection/IterableFactory#apply().
4069+
[16:7..16:11): test <- _empty_/test.
4070+
[17:7..17:15): Concrete -> _empty_/Concrete#
4071+
[17:15..17:15): -> _empty_/Concrete#`<init>`().
4072+
[17:17..17:25): nullary2 -> _empty_/Concrete#nullary2().
4073+
[18:7..18:15): Concrete -> _empty_/Concrete#
4074+
[18:15..18:15): -> _empty_/Concrete#`<init>`().
4075+
[18:17..18:25): nullary3 -> _empty_/Concrete#nullary3().
4076+
39314077
expect/recursion.scala
39324078
----------------------
39334079

0 commit comments

Comments
 (0)