Skip to content

Commit 32a04c8

Browse files
Fixes for 2 code quality findings (#25960)
_This PR applies 2/2 suggestions from code quality [AI findings](https://github.com/scala/scala3/security/quality/ai-findings)._ (I reviewed those, they make sense; I'm not opening PRs for some of the other, more dubious, findings) --------- Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
1 parent 897f098 commit 32a04c8

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
273273
val (rtp, paramss) = recur(tp.instantiate(tparams.map(_.typeRef)), remaining1)
274274
(rtp, tparams :: paramss)
275275
case tp: MethodType =>
276-
val isParamDependent = tp.isParamDependent
277-
val previousParamRefs: mutable.ListBuffer[TermRef] =
278-
// It is ok to assign `null` here.
279-
// If `isParamDependent == false`, the value of `previousParamRefs` is not used.
280-
if isParamDependent then mutable.ListBuffer[TermRef]() else (null: mutable.ListBuffer[TermRef] | Null).uncheckedNN
276+
val previousParamRefs: mutable.ListBuffer[TermRef] | Null =
277+
if tp.isParamDependent then mutable.ListBuffer[TermRef]() else null
281278

282279
def valueParam(name: TermName, origInfo: Type, isErased: Boolean): TermSymbol =
283280
val maybeImplicit =
@@ -288,7 +285,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
288285

289286
def makeSym(info: Type) = newSymbol(sym, name, TermParam | maybeImplicit | maybeErased, info, coord = sym.coord)
290287

291-
if isParamDependent then
288+
if previousParamRefs ne null then
292289
val sym = makeSym(origInfo.substParams(tp, previousParamRefs.toList))
293290
previousParamRefs += sym.termRef
294291
sym
@@ -1415,7 +1412,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
14151412

14161413
@tailrec
14171414
def sameTypes(trees: List[tpd.Tree], trees1: List[tpd.Tree]): Boolean =
1418-
if (trees.isEmpty) trees.isEmpty
1415+
if (trees.isEmpty) trees1.isEmpty
14191416
else if (trees1.isEmpty) trees.isEmpty
14201417
else (trees.head.tpe eq trees1.head.tpe) && sameTypes(trees.tail, trees1.tail)
14211418

tests/semanticdb/metac.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5304,8 +5304,8 @@ local1 => val local p: N$1
53045304
local2 => type N$2 <: Nat
53055305
local3 => val local p: N$2
53065306
local4 => val local Nat_this: Zero.type
5307-
local5 => val local Nat_this: Succ[Zero.type]
5308-
local6 => val local Nat_this: Succ[_] forSome { type _ <: Succ[Zero.type] }
5307+
local5 => val local Nat_this: Succ[Nat_this.type]
5308+
local6 => val local Nat_this: Succ[Nat_this.type]
53095309
recursion/Nats. => final object Nats extends Object { self: Nats.type => +9 decls }
53105310
recursion/Nats.Nat# => sealed trait Nat extends Object { self: Nat => +3 decls }
53115311
recursion/Nats.Nat#`++`(). => inline transparent macro ++ => Succ[Nat.this.type]

0 commit comments

Comments
 (0)