Skip to content

Commit

Permalink
Guard against extension suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Apr 6, 2024
1 parent 2bc7faf commit bd9de74
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Expand Up @@ -1754,7 +1754,7 @@ abstract class RefChecks extends Transform {
h.count {
case treeInfo.Applied(getter, _, _) if getter.symbol != null && getter.symbol.isDefaultGetter =>
val (_, i) = nme.splitDefaultGetterName(getter.symbol.name)
isNameableBoolean(allParams(i-1))
i > 0 && isNameableBoolean(allParams(i-1))
case _ => false
}
case _ => 0
Expand Down
7 changes: 6 additions & 1 deletion src/reflect/scala/reflect/internal/StdNames.scala
Expand Up @@ -551,7 +551,12 @@ trait StdNames {
case -1 => (name.toTermName, -1)
case idx => (name.toTermName.take(idx), idx + DEFAULT_GETTER_STRING.length)
}
if (i >= 0) (n, name.encoded.substring(i).toInt) else (n, -1)
if (i < 0) (n, -1)
else {
val j = name.indexOf('$', i) // f$default$7$extension
val idx = name.subSequence(i, if (j < 0) name.length else j)
(n, idx.toString.toInt)
}
}

def localDummyName(clazz: Symbol): TermName = newTermName(LOCALDUMMY_PREFIX + clazz.name + ">")
Expand Down
5 changes: 4 additions & 1 deletion test/files/neg/named-booleans-relaxed.check
Expand Up @@ -46,6 +46,9 @@ named-booleans-relaxed.scala:92: warning: Boolean literals should be passed usin
named-booleans-relaxed.scala:95: warning: Boolean literals should be passed using named argument syntax for parameter x. [quickfixable]
def f = p.f(true, z=42) // warn
^
named-booleans-relaxed.scala:106: warning: Boolean literals should be passed using named argument syntax for parameter y. [quickfixable]
def w = new V(true).combo(false)
^
error: No warnings can be incurred under -Werror.
16 warnings
17 warnings
1 error
9 changes: 9 additions & 0 deletions test/files/neg/named-booleans-relaxed.scala
Expand Up @@ -96,3 +96,12 @@ object TestPrinters {
def g = p.f(x=true, b=true) // nowarn, no unnamed
def h = p.f(true, b=true) // nowarn, one unnamed but other boolean is named; defaults are non-boolean
}

object Testy {
class V(val x: Boolean) extends AnyVal {
def combo(y: Boolean = true, z: Boolean = false) = x&&y&&z
}

def v = new V(true)
def w = new V(true).combo(false)
}

0 comments on commit bd9de74

Please sign in to comment.