Skip to content

E161 naming error during second compilation of project #23043

Open
@rssh

Description

@rssh
Contributor

Compiler version

Scala-3.3.5
alse reproduced at the latest master

reproduction

Unfortunelly, I was unhappy to minimize (because after any significatn minimization issue is gone), but here is a 'long way':

git clone git@github.com:nau/scalus.git
cd scalus
git checkout dotty-naming-issue-2024-04-24

sbt scalusJVM/test:compile   ## success. [wait a minute or two]

echo // >> shared/src/test/scala/scalus/prelude/DerivingSpec.scala

sbt scalusJVM/test:compile  ## failure

Output

[error] -- [E161] Naming Error: /Users/rssh/tests/dotty/naming-issue-scalus-report/scalus/shared/src/test/scala/scalus/prelude/DerivingSpec.scala:18:7 
[error] 18 |object DerivingSpecScope {
[error]    |^
[error]    |DerivingSpecScope is already defined as package scalus.prelude.DerivingSpecScope
[error] 19 |    enum AE1 derives ToData, FromData:
[error] 20 |        case A extends AE1
[error] 21 |        case B(b: BigInt) extends AE1
[error] 22 |        case C(b: BigInt, bs: ByteString) extends AE1
[error] 23 |}
[error] -- [E006] Not Found Error: /Users/rssh/tests/dotty/naming-issue-scalus-report/scalus/shared/src/test/scala/scalus/prelude/DerivingSpec.scala:36:51 
[error] 36 |            val a = summon[scalus.prelude.FromData[AE1]](d)
[error]    |                                                   ^^^
[error]    |                                                   Not found: type AE1
[error]    |----------------------------------------------------------------------------
[error]    | Explanation (enabled by `-explain`)
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    | Each identifier in Scala needs a matching declaration. There are two kinds of
[error]    | identifiers: type identifiers and value identifiers. Value identifiers are introduced
[error]    | by `val`, `def`, or `object` declarations. Type identifiers are introduced by `type`,
[error]    | `class`, `enum`, or `trait` declarations.
[error]    |
[error]    | Identifiers refer to matching declarations in their environment, or they can be
[error]    | imported from elsewhere.
[error]    |
[error]    | Possible reasons why no matching declaration was found:
[error]    |  - The declaration or the use is mis-spelt.
[error]    |  - An import is missing.
[error]     ----------------------------------------------------------------------------
[error] -- [E006] Not Found Error: /Users/rssh/tests/dotty/naming-issue-scalus-report/scalus/shared/src/test/scala/scalus/prelude/DerivingSpec.scala:38:21 
[error] 38 |                case AE1.A        => BigInt(1)
[error]    |                     ^^^
[error]    |                     Not found: AE1
[error]    |----------------------------------------------------------------------------
[error]    | Explanation (enabled by `-explain`)
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    | Each identifier in Scala needs a matching declaration. There are two kinds of
[error]    | identifiers: type identifiers and value identifiers. Value identifiers are introduced
[error]    | by `val`, `def`, or `object` declarations. Type identifiers are introduced by `type`,
[error]    | `class`, `enum`, or `trait` declarations.
[error]    |
[error]    | Identifiers refer to matching declarations in their environment, or they can be
[error]    | imported from elsewhere.
[error]    |
[error]    | Possible reasons why no matching declaration was found:
[error]    |  - The declaration or the use is mis-spelt.
[error]    |  - An import is missing.
....

Expectation

The second time should also compile.

Activity

rssh

rssh commented on Apr 24, 2025

@rssh
ContributorAuthor

Here is a fix which at least make all compile: #23044

added a commit that references this issue on Apr 24, 2025
fb1272c
linked a pull request that will close this issuefix #23043 #23044on Apr 24, 2025
rssh

rssh commented on Apr 24, 2025

@rssh
ContributorAuthor

oops, looks like fix is not enough

rssh

rssh commented on Apr 25, 2025

@rssh
ContributorAuthor

fix updated

som-snytt

som-snytt commented on May 13, 2025

@som-snytt
Contributor

On recompile, Namer thinks
pre of DerivingSpecScope$ in module class prelude is module class DerivingSpecScope$
is(Package). // preExisting.lastKnownDenotation.is(Package)

That is obviously wrong.

There are also suspicious warnings.

[warn] /home/amarki/snips/nau-scalus/shared/src/main/scala/scalus/builtin/FromData.scala:96:67: Constructor symbol not found: scalus.prelude.DerivingSpec_AE2
[warn]         '{ (args: scalus.builtin.List[scalus.builtin.Data]) => ${ genConstructorCall('{ args }) } }

that is associated with this suspicious comment

        def genConstructorCall(
            a: Expr[scalus.builtin.List[scalus.builtin.Data]]
        )(using Quotes): Expr[T] = {
            val args = fromDataOfArgs.zipWithIndex.map { case (appl, idx) =>
                val arg = genGetter(a, idx)
                '{ $appl($arg) }.asTerm
            }
            // Couldn't find a way to do this using quotes, so just construct the tree manually
            New(TypeTree.of[T]).select(constr).appliedToArgs(args).asExprOf[T]
        }
        '{ (args: scalus.builtin.List[scalus.builtin.Data]) => ${ genConstructorCall('{ args }) } }

Sorry I have no idea if it means anything or what conclusion to draw. I assume the PR is misguided because the bug lies in the construction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @rssh@som-snytt@Gedochao

      Issue actions

        E161 naming error during second compilation of project · Issue #23043 · scala/scala3