Skip to content

Commit bfbe08d

Browse files
committed
Resupport Ident patterns in pattern defs
1 parent 057b158 commit bfbe08d

File tree

4 files changed

+67
-50
lines changed

4 files changed

+67
-50
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class ExtractSemanticDB extends Phase with
165165
// ignore rhs
166166
case PatternValDef(pat, rhs) =>
167167
traverse(rhs)
168-
PatternValDef.collectUnapplyFuncs(pat).foreach(traverse)
168+
PatternValDef.collectPats(pat).foreach(traverse)
169169
case tree =>
170170
if !excludeChildren(tree.symbol)
171171
traverseChildren(tree)
@@ -236,14 +236,17 @@ class ExtractSemanticDB extends Phase with
236236
case Types.AnnotatedType(_, annot) => annot.symbol == defn.UncheckedAnnot
237237
case _ => false
238238

239-
def collectUnapplyFuncs(pat: Tree): List[Tree] =
239+
def collectPats(pat: Tree): List[Tree] =
240240

241241
@tailrec
242242
def impl(acc: List[Tree], pats: List[Tree]): List[Tree] = pats match
243+
243244
case pat::pats => pat match
244-
case Typed(UnApply(fun: Tree, _, args), _) => impl(fun::acc, args:::pats)
245-
case UnApply(fun: Tree, _, args) => impl(fun::acc, args:::pats)
246-
case _ => impl(acc, pats)
245+
case Typed(UnApply(fun: Tree, _, args), tpt: Tree) => impl(fun::tpt::acc, args:::pats)
246+
case Typed(obj: Ident, tpt: Tree) => impl(obj::tpt::acc, pats)
247+
case UnApply(fun: Tree, _, args) => impl(fun::acc, args:::pats)
248+
case obj: Ident => impl(obj::acc, pats)
249+
case _ => impl(acc, pats)
247250

248251
case Nil => acc
249252

tests/semanticdb/expect/ValPattern.expect.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class ValPattern/*<-example::ValPattern#*/ {
66
val Some/*->scala::Some.*//*->scala::Some.unapply().*/(number1/*<-example::ValPattern#number1.*/) =
77
Some/*->scala::Some.*//*->scala::Some.apply().*/(1)
88

9+
val List/*->scala::package.List.*//*->scala::collection::SeqFactory#unapplySeq().*/(Some/*->scala::Some.*//*->scala::Some.unapply().*/(q1/*<-example::ValPattern#q1.*/), None/*->scala::None.*/: None/*->scala::None.*/.type, None/*->scala::None.*/) = ???/*->scala::Predef.`???`().*/
10+
911
var (leftVar/*<-example::ValPattern#leftVar().*/, rightVar/*<-example::ValPattern#rightVar().*/) = (/*->scala::Tuple2.apply().*/1, 2)
1012
var Some/*->scala::Some.*//*->scala::Some.unapply().*/(number1Var/*<-example::ValPattern#number1Var().*/) =
1113
Some/*->scala::Some.*//*->scala::Some.apply().*/(1)

tests/semanticdb/expect/ValPattern.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class ValPattern {
66
val Some(number1) =
77
Some(1)
88

9+
val List(Some(q1), None: None.type, None) = ???
10+
911
var (leftVar, rightVar) = (1, 2)
1012
var Some(number1Var) =
1113
Some(1)

tests/semanticdb/metac.expect

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,8 +3099,8 @@ Schema => SemanticDB v4
30993099
Uri => ValPattern.scala
31003100
Text => empty
31013101
Language => Scala
3102-
Symbols => 21 entries
3103-
Occurrences => 54 entries
3102+
Symbols => 22 entries
3103+
Occurrences => 63 entries
31043104

31053105
Symbols:
31063106
example/ValPattern# => class ValPattern
@@ -3116,6 +3116,7 @@ example/ValPattern#left. => val method left
31163116
example/ValPattern#leftVar(). => var method leftVar
31173117
example/ValPattern#number1. => val method number1
31183118
example/ValPattern#number1Var(). => var method number1Var
3119+
example/ValPattern#q1. => val method q1
31193120
example/ValPattern#right. => val method right
31203121
example/ValPattern#rightVar(). => var method rightVar
31213122
local0 => val local left
@@ -3137,49 +3138,58 @@ Occurrences:
31373138
[5:11..5:18): number1 <- example/ValPattern#number1.
31383139
[6:4..6:8): Some -> scala/Some.
31393140
[6:8..6:8): -> scala/Some.apply().
3140-
[8:7..8:14): leftVar <- example/ValPattern#leftVar().
3141-
[8:16..8:24): rightVar <- example/ValPattern#rightVar().
3142-
[8:29..8:29): -> scala/Tuple2.apply().
3143-
[9:6..9:10): Some -> scala/Some.
3144-
[9:10..9:10): -> scala/Some.unapply().
3145-
[9:11..9:21): number1Var <- example/ValPattern#number1Var().
3146-
[10:4..10:8): Some -> scala/Some.
3147-
[10:8..10:8): -> scala/Some.apply().
3148-
[12:6..12:9): app <- example/ValPattern#app().
3149-
[12:13..12:17): Unit -> scala/Unit#
3150-
[13:4..13:11): println -> scala/Predef.println(+1).
3151-
[15:8..15:8): -> scala/Tuple6.apply().
3152-
[15:8..15:15): number1 -> example/ValPattern#number1.
3153-
[16:8..16:12): left -> example/ValPattern#left.
3154-
[17:8..17:13): right -> example/ValPattern#right.
3155-
[18:8..18:18): number1Var -> example/ValPattern#number1Var().
3156-
[19:8..19:15): leftVar -> example/ValPattern#leftVar().
3157-
[20:8..20:16): rightVar -> example/ValPattern#rightVar().
3158-
[23:4..23:11): locally -> dotty/DottyPredef.locally().
3159-
[24:11..24:15): left <- local0
3160-
[24:17..24:22): right <- local1
3161-
[24:27..24:27): -> scala/Tuple2.apply().
3162-
[25:10..25:14): Some -> scala/Some.
3163-
[25:14..25:14): -> scala/Some.unapply().
3164-
[25:15..25:22): number1 <- local2
3165-
[26:8..26:12): Some -> scala/Some.
3166-
[26:12..26:12): -> scala/Some.apply().
3167-
[28:11..28:18): leftVar <- local3
3168-
[28:20..28:28): rightVar <- local4
3169-
[28:33..28:33): -> scala/Tuple2.apply().
3170-
[29:10..29:14): Some -> scala/Some.
3171-
[29:14..29:14): -> scala/Some.unapply().
3172-
[29:15..29:25): number1Var <- local5
3173-
[30:8..30:12): Some -> scala/Some.
3174-
[30:12..30:12): -> scala/Some.apply().
3175-
[31:6..31:13): println -> scala/Predef.println(+1).
3176-
[33:10..33:10): -> scala/Tuple6.apply().
3177-
[33:10..33:17): number1 -> local2
3178-
[34:10..34:14): left -> local0
3179-
[35:10..35:15): right -> local1
3180-
[36:10..36:20): number1Var -> local5
3181-
[37:10..37:17): leftVar -> local3
3182-
[38:10..38:18): rightVar -> local4
3141+
[8:6..8:10): List -> scala/package.List.
3142+
[8:10..8:10): -> scala/collection/SeqFactory#unapplySeq().
3143+
[8:11..8:15): Some -> scala/Some.
3144+
[8:15..8:15): -> scala/Some.unapply().
3145+
[8:16..8:18): q1 <- example/ValPattern#q1.
3146+
[8:21..8:25): None -> scala/None.
3147+
[8:27..8:31): None -> scala/None.
3148+
[8:38..8:42): None -> scala/None.
3149+
[8:46..8:49): ??? -> scala/Predef.`???`().
3150+
[10:7..10:14): leftVar <- example/ValPattern#leftVar().
3151+
[10:16..10:24): rightVar <- example/ValPattern#rightVar().
3152+
[10:29..10:29): -> scala/Tuple2.apply().
3153+
[11:6..11:10): Some -> scala/Some.
3154+
[11:10..11:10): -> scala/Some.unapply().
3155+
[11:11..11:21): number1Var <- example/ValPattern#number1Var().
3156+
[12:4..12:8): Some -> scala/Some.
3157+
[12:8..12:8): -> scala/Some.apply().
3158+
[14:6..14:9): app <- example/ValPattern#app().
3159+
[14:13..14:17): Unit -> scala/Unit#
3160+
[15:4..15:11): println -> scala/Predef.println(+1).
3161+
[17:8..17:8): -> scala/Tuple6.apply().
3162+
[17:8..17:15): number1 -> example/ValPattern#number1.
3163+
[18:8..18:12): left -> example/ValPattern#left.
3164+
[19:8..19:13): right -> example/ValPattern#right.
3165+
[20:8..20:18): number1Var -> example/ValPattern#number1Var().
3166+
[21:8..21:15): leftVar -> example/ValPattern#leftVar().
3167+
[22:8..22:16): rightVar -> example/ValPattern#rightVar().
3168+
[25:4..25:11): locally -> dotty/DottyPredef.locally().
3169+
[26:11..26:15): left <- local0
3170+
[26:17..26:22): right <- local1
3171+
[26:27..26:27): -> scala/Tuple2.apply().
3172+
[27:10..27:14): Some -> scala/Some.
3173+
[27:14..27:14): -> scala/Some.unapply().
3174+
[27:15..27:22): number1 <- local2
3175+
[28:8..28:12): Some -> scala/Some.
3176+
[28:12..28:12): -> scala/Some.apply().
3177+
[30:11..30:18): leftVar <- local3
3178+
[30:20..30:28): rightVar <- local4
3179+
[30:33..30:33): -> scala/Tuple2.apply().
3180+
[31:10..31:14): Some -> scala/Some.
3181+
[31:14..31:14): -> scala/Some.unapply().
3182+
[31:15..31:25): number1Var <- local5
3183+
[32:8..32:12): Some -> scala/Some.
3184+
[32:12..32:12): -> scala/Some.apply().
3185+
[33:6..33:13): println -> scala/Predef.println(+1).
3186+
[35:10..35:10): -> scala/Tuple6.apply().
3187+
[35:10..35:17): number1 -> local2
3188+
[36:10..36:14): left -> local0
3189+
[37:10..37:15): right -> local1
3190+
[38:10..38:20): number1Var -> local5
3191+
[39:10..39:17): leftVar -> local3
3192+
[40:10..40:18): rightVar -> local4
31833193

31843194
expect/Vals.scala
31853195
-----------------

0 commit comments

Comments
 (0)