Support minus sign in project names

Previously, sbt would crash when attempting to load a build where
projects had minus signs (`-`) in their name.

For instance, when trying to load a project defined like this:

    lazy val `my-project` = project

After compilation, this definition looks somewhat like this

    val my$minusproject$lzy1 = ...

sbt was attempting to retrieve the original definition (without the $lzy
suffix) by taking the mangled name up to the first `$`. Unfortunately,
this approach does not work when the name includes special characters
like a minus sign, because these will be prefixed with `$` as well. In
the current example, sbt would then try to find the member named `my`,
fail, and crash.

This patch fixes the issue by using the "underlying" name, which is the
name without the additional information.
This commit is contained in:
Martin Duhem 2025-06-26 10:09:42 +02:00
parent 1a06f29d0b
commit 79dbcd2ff4
No known key found for this signature in database
GPG Key ID: 7AED2383601007B6
4 changed files with 6 additions and 5 deletions

View File

@ -5,7 +5,7 @@ import dotty.tools.dotc.ast
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.CompilationUnit
import dotty.tools.dotc.core.Contexts.{ atPhase, Context }
import dotty.tools.dotc.core.{ Flags, Names, Phases, Symbols, Types }
import dotty.tools.dotc.core.{ Flags, NameKinds, Names, Phases, Symbols, Types }
import dotty.tools.dotc.Driver
import dotty.tools.dotc.Run
import dotty.tools.dotc.util.SourceFile
@ -391,11 +391,10 @@ object Eval:
case tpd.ValDef(name, tpt, _)
if isTopLevelModule(tree.symbol.owner) && isAcceptableType(tpt.tpe) =>
vals ::= name.mangledString
case tpd.ValDef(name, tpt, _) if name.mangledString.contains("$lzy") =>
val str = name.mangledString
val methodName = str.take(str.indexOf("$"))
case tpd.ValDef(name, tpt, _) if name.is(NameKinds.LazyLocalName) =>
val methodName = name.underlying
val m = tree.symbol.owner.requiredMethod(methodName)
if isAcceptableType(m.info) then vals ::= methodName
if isAcceptableType(m.info) then vals ::= methodName.mangledString
case t: tpd.Template => this((), t.body)
case t: tpd.PackageDef => this((), t.stats)
case t: tpd.TypeDef => this((), t.rhs)

View File

@ -0,0 +1 @@
lazy val `a-funky-name` = project

View File

@ -0,0 +1 @@
> name