Skip to content

Commit f7a5aca

Browse files
authored
Merge pull request #513 from scala/backport-lts-3.3-23508
Backport "Guard against invalid prefixes in argForParam" to 3.3 LTS
2 parents afb083a + 1a3d5ce commit f7a5aca

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,7 @@ object Types extends TypeUtils {
22612261
def _1: Type
22622262
def _2: Designator
22632263

2264-
assert(NamedType.validPrefix(prefix), s"invalid prefix $prefix")
2264+
if !NamedType.validPrefix(prefix) then throw InvalidPrefix()
22652265

22662266
private var myName: Name | Null = null
22672267
private var lastDenotation: Denotation | Null = null
@@ -2683,7 +2683,7 @@ object Types extends TypeUtils {
26832683
if (tparams.head.eq(tparam))
26842684
return args.head match {
26852685
case _: TypeBounds if !widenAbstract => TypeRef(pre, tparam)
2686-
case arg => arg.boxedUnlessFun(tycon)
2686+
case arg => arg
26872687
}
26882688
tparams = tparams.tail
26892689
args = args.tail
@@ -3038,6 +3038,8 @@ object Types extends TypeUtils {
30383038
apply(prefix, designatorFor(prefix, name, denot)).withDenot(denot)
30393039
}
30403040

3041+
class InvalidPrefix extends Exception
3042+
30413043
// --- Other SingletonTypes: ThisType/SuperType/ConstantType ---------------------------
30423044

30433045
/** The type cls.this

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package core
33

44
import Types.*, Contexts.*, util.Stats.*, Hashable.*, Names.*
55
import config.Config
6+
import Symbols.Symbol
67
import Decorators.*
78
import util.{WeakHashSet, Stats}
89
import WeakHashSet.Entry
@@ -41,8 +42,10 @@ object Uniques:
4142
val h = doHash(null, designator, prefix)
4243
if monitored then recordCaching(h, classOf[NamedType])
4344
def newType =
44-
if (isTerm) new CachedTermRef(prefix, designator, h)
45-
else new CachedTypeRef(prefix, designator, h)
45+
try
46+
if isTerm then new CachedTermRef(prefix, designator, h)
47+
else new CachedTypeRef(prefix, designator, h)
48+
catch case ex: InvalidPrefix => badPrefix(prefix, designator)
4649
if h == NotCached then newType
4750
else
4851
// Inlined from WeakHashSet#put
@@ -61,6 +64,14 @@ object Uniques:
6164

6265
linkedListLoop(oldHead)
6366
end if
67+
end enterIfNew
68+
69+
private def badPrefix(prefix: Type, desig: Designator)(using Context): Nothing =
70+
def name = desig match
71+
case desig: Name => desig
72+
case desig: Symbol => desig.name
73+
throw TypeError(em"invalid prefix $prefix when trying to form $prefix . $name")
74+
6475
end NamedTypeUniques
6576

6677
final class AppliedUniques extends WeakHashSet[AppliedType](Config.initialUniquesCapacity * 2) with Hashable:

tests/neg/i23504.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def test =
2+
Seq.empty[[T] =>> () => ?].head() // error
3+
Seq.empty[[T] =>> Int => Int].head(1) // error

0 commit comments

Comments
 (0)