Skip to content

Commit 2dfe63c

Browse files
committed
Align unpickled Scala 2 accessors encoding with Scala 3
1 parent 438bd01 commit 2dfe63c

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
456456
// skip this member
457457
return NoSymbol
458458

459+
// Adapt the flags of getters so they become like vals/vars instead
460+
if flags.isAllOf(Method | Accessor) && !name.toString().endsWith("_$eq") then
461+
flags &~= Method | Accessor
462+
if !flags.is(StableRealizable) then flags |= Mutable
463+
459464
name = name.adjustIfModuleClass(flags)
460465
if (flags.is(Method))
461466
name =
@@ -620,7 +625,12 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
620625
setClassInfo(denot, tp, fromScala2 = true, selfInfo)
621626
NamerOps.addConstructorProxies(denot.classSymbol)
622627
case denot =>
623-
val tp1 = translateTempPoly(tp)
628+
val tp0 = translateTempPoly(tp)
629+
val tp1 =
630+
if !denot.is(Param) && !denot.is(Method) && tp0.isInstanceOf[ExprType] then
631+
tp0.asInstanceOf[ExprType].resultType
632+
else tp0
633+
624634
denot.info =
625635
if (tag == ALIASsym) TypeAlias(tp1)
626636
else if (denot.isType) checkNonCyclic(denot.symbol, tp1, reportErrors = false)

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionDocSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class CompletionDocSuite extends BaseCompletionSuite:
214214
""".stripMargin,
215215
"""
216216
|> Found documentation for scala/package.Vector.
217-
|Vector scala.collection.immutable
217+
|Vector: scala.collection.immutable
218218
|""".stripMargin,
219219
includeDocs = true
220220
)

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CompletionSuite extends BaseCompletionSuite:
2525
| Lis@@
2626
|}""".stripMargin,
2727
"""
28-
|List scala.collection.immutable
28+
|List: scala.collection.immutable
2929
|List - java.awt
3030
|List - java.util
3131
|List - scala.collection.immutable
@@ -647,7 +647,7 @@ class CompletionSuite extends BaseCompletionSuite:
647647
|}
648648
|""".stripMargin,
649649
"""|None scala
650-
|NoManifest scala.reflect
650+
|NoManifest: scala.reflect
651651
|""".stripMargin,
652652
topLines = Some(2)
653653
)
@@ -660,8 +660,8 @@ class CompletionSuite extends BaseCompletionSuite:
660660
|}
661661
|""".stripMargin,
662662
"""|Some(value) scala
663-
|Seq scala.collection.immutable
664-
|Set scala.collection.immutable
663+
|Seq: scala.collection.immutable
664+
|Set: scala.collection.immutable
665665
|""".stripMargin,
666666
topLines = Some(3)
667667
)

presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
194194
s"""|package <<example>>/*namespace*/
195195
|
196196
|object <<A>>/*class*/ {
197-
| val <<x>>/*variable,definition,readonly*/ = <<List>>/*class*/(1,2,3)
197+
| val <<x>>/*variable,definition,readonly*/ = <<List>>/*variable,readonly*/(1,2,3)
198198
| val <<s>>/*variable,definition,readonly*/ = <<Some>>/*class*/(1)
199199
| val <<Some>>/*class*/(<<s1>>/*variable,definition,readonly*/) = <<s>>/*variable,readonly*/
200200
| val <<Some>>/*class*/(<<s2>>/*variable,definition,readonly*/) = <<s>>/*variable,readonly*/
@@ -269,7 +269,7 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
269269
|object <<A>>/*class*/ {
270270
| val <<a>>/*variable,definition,readonly*/ = 1
271271
| var <<b>>/*variable,definition*/ = 2
272-
| val <<c>>/*variable,definition,readonly*/ = <<List>>/*class*/(1,<<a>>/*variable,readonly*/,<<b>>/*variable*/)
272+
| val <<c>>/*variable,definition,readonly*/ = <<List>>/*variable,readonly*/(1,<<a>>/*variable,readonly*/,<<b>>/*variable*/)
273273
| <<b>>/*variable*/ = <<a>>/*variable,readonly*/
274274
|""".stripMargin
275275
)
@@ -278,10 +278,10 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
278278
check(
279279
"""
280280
|object <<Main>>/*class*/ {
281-
| val <<a>>/*variable,definition,readonly*/ = <<List>>/*class*/(1,2,3)
282-
| val <<y>>/*variable,definition,readonly*/ = <<Vector>>/*class*/(1,2)
283-
| val <<z>>/*variable,definition,readonly*/ = <<Set>>/*class*/(1,2,3)
284-
| val <<w>>/*variable,definition,readonly*/ = <<Right>>/*class*/(1)
281+
|val <<a>>/*variable,definition,readonly*/ = <<List>>/*variable,readonly*/(1,2,3)
282+
|val <<y>>/*variable,definition,readonly*/ = <<Vector>>/*variable,readonly*/(1,2)
283+
|val <<z>>/*variable,definition,readonly*/ = <<Set>>/*variable,readonly*/(1,2,3)
284+
|val <<w>>/*variable,definition,readonly*/ = <<Right>>/*variable,readonly*/(1)
285285
|}""".stripMargin
286286
)
287287

@@ -326,7 +326,7 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
326326
|
327327
|object <<B>>/*class*/ {
328328
| val <<a>>/*variable,definition,readonly*/ = for {
329-
| <<foo>>/*variable,definition,readonly*/ <- <<List>>/*class*/("a", "b", "c")
329+
| <<foo>>/*variable,definition,readonly*/ <- <<List>>/*variable,readonly*/("a", "b", "c")
330330
| <<_>>/*class,abstract*/ = <<println>>/*method*/("print!")
331331
| } yield <<foo>>/*variable,readonly*/
332332
|}

tests/neg/constructor-proxy-shadowing.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
17 |val x = Seq(3) // error: shadowing
5353
| ^^^
5454
| Reference to constructor proxy for class Seq
55-
| shadows outer reference to getter Seq in package scala
55+
| shadows outer reference to value Seq in package scala
5656
|
5757
| The instance needs to be created with an explicit `new`.
5858
|--------------------------------------------------------------------------------------------------------------------
@@ -66,7 +66,7 @@
6666
|
6767
| new Seq(...)
6868
|
69-
| Or it could mean calling the apply method of getter Seq in package scala as in
69+
| Or it could mean calling the apply method of value Seq in package scala as in
7070
|
7171
| Seq.apply(...)
7272
|

0 commit comments

Comments
 (0)