Skip to content

Commit cd2b23a

Browse files
committed
Fix #7416: Don't emit signatures of fields of primitive types
Don't emit signatures for private fields of primitive type
1 parent dacfba8 commit cd2b23a

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ object TypeErasure {
147147
def valueErasure(tp: Type)(implicit ctx: Context): Type =
148148
erasureFn(isJava = false, semiEraseVCs = true, isConstructor = false, wildcardOK = false)(tp)(erasureCtx)
149149

150+
/** Like value class erasure, but value classes erase to their underlying type erasure */
151+
def fullErasure(tp: Type)(implicit ctx: Context): Type =
152+
valueErasure(tp) match
153+
case ErasedValueType(_, underlying) => erasure(underlying)
154+
case etp => etp
155+
150156
def sigName(tp: Type, isJava: Boolean)(implicit ctx: Context): TypeName = {
151157
val normTp = tp.underlyingIfRepeated(isJava)
152158
val erase = erasureFn(isJava, semiEraseVCs = false, isConstructor = false, wildcardOK = true)

compiler/src/dotty/tools/dotc/transform/CapturedVars.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
2323
/** the following two members override abstract members in Transform */
2424
val phaseName: String = "capturedVars"
2525

26-
private var Captured: Store.Location[collection.Set[Symbol]] = _
26+
private[this] var Captured: Store.Location[collection.Set[Symbol]] = _
2727
private def captured(implicit ctx: Context) = ctx.store(Captured)
2828

2929
override def initContext(ctx: FreshContext): Unit =
@@ -82,7 +82,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
8282
*/
8383
def refClass(cls: Symbol, isVolatile: Boolean)(implicit ctx: Context): Symbol = {
8484
val refMap = if (isVolatile) refInfo.volatileRefClass else refInfo.refClass
85-
if (cls.isClass)
85+
if (cls.isClass)
8686
refMap.getOrElse(cls, refMap(defn.ObjectClass))
8787
else refMap(defn.ObjectClass)
8888
}

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import core.Flags._
99
import core.Names.{DerivedName, Name, SimpleName, TypeName}
1010
import core.Symbols._
1111
import core.TypeApplications.TypeParamInfo
12-
import core.TypeErasure.erasure
12+
import core.TypeErasure.{erasure, fullErasure}
1313
import core.Types._
1414
import core.classfile.ClassfileConstants
1515
import ast.Trees._
1616
import SymUtils._
1717
import TypeUtils._
1818
import java.lang.StringBuilder
19+
import core.Decorators._
1920

2021
import scala.annotation.tailrec
2122

@@ -33,7 +34,12 @@ object GenericSignatures {
3334
*/
3435
def javaSig(sym0: Symbol, info: Type)(implicit ctx: Context): Option[String] =
3536
// Avoid generating a signature for local symbols.
36-
if (sym0.isLocal) None
37+
// Also suppress signatures for private symbols whose types erase in the end to primitive
38+
// value types. This is done to fix #7416. Since I do not know GenericSignatures well,
39+
// I did a minimal fix that lets #7416 pass. Maybe it can be generalized
40+
if sym0.isLocal
41+
|| sym0.is(Private) && fullErasure(info).isPrimitiveValueType
42+
then None
3743
else javaSig0(sym0, info)(ctx.withPhase(ctx.erasurePhase))
3844

3945
@noinline

0 commit comments

Comments
 (0)