java-topology/defects/scala/patch/scala-0001.patch

20 lines
1.1 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# UNDF: UNDF-2026-000000270
diff --git a/src/compiler/scala/tools/nsc/typechecker/Checkable.scala b/src/compiler/scala/tools/nsc/typechecker/Checkable.scala
index abcdef00..cwe407fix 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Checkable.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Checkable.scala
@@ -98,7 +98,11 @@ trait Checkable {
def propagateKnownTypes(from: Type, to: Symbol): Type = {
def tparams = to.typeParams
val tvars = tparams map (p => TypeVar(p))
val tvarType = appliedType(to, tvars)
+ // CWE-407 fix: convert to.baseClasses to a Set before the outer foreach.
+ // Previously: from.baseClasses foreach { bc => if (to.baseClasses.contains(bc))
+ // was O(M×N) where M=|from.baseClasses|, N=|to.baseClasses| — both are List[Symbol].
+ // Symbol equality is reference identity so Set[Symbol] is O(1) contains.
+ val toBaseSet = to.baseClasses.toSet
- from.baseClasses foreach { bc => if (to.baseClasses.contains(bc)){
+ from.baseClasses foreach { bc => if (toBaseSet.contains(bc)){
val tps1 = (from baseType bc).typeArgs
val tps2 = (tvarType baseType bc).typeArgs