Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum Overloading Regression? #23596

Closed
c-blake opened this issue May 11, 2024 · 4 comments · Fixed by #23597
Closed

Enum Overloading Regression? #23596

c-blake opened this issue May 11, 2024 · 4 comments · Fixed by #23597

Comments

@c-blake
Copy link
Contributor

c-blake commented May 11, 2024

Description

import std/heapqueue
type Algo = enum heapqueue, quick
proc bar*(algo=quick) =
  var x: HeapQueue[int]
  case algo
  of heapqueue: echo 1 # `Algo.heapqueue` works on devel
  of quick: echo 2
  echo x.len

Nim Version

nim-devel c91b33a

Current Output

foo.nim(6, 6) Error: expression 'heapqueue' has no type (or is ambiguous)

Expected Output

Nim compilers only a couple weeks older work without needing the `Algo.` qualification.

Possible Solution

I expect but do not know that this relates to @ringabout's recent enum work. It's probably an easy git bisect. It worked in nim-devel 6cb2dca which I only kept around for backend portability-performance investigation.

Additional Information

I think this is distinct from #23579 . I'm also not sure if it's exactly unintended behavior. Maybe nim core wants the qualification to be required in this case. It seemed worth reporting while the work is fresh.

@juancarlospaco
Copy link
Collaborator

!nim c

import std/heapqueue
type Algo = enum heapqueue, quick
proc bar*(algo=quick) =
  var x: HeapQueue[int]
  case algo
  of heapqueue: echo 1
  of quick: echo 2
  echo x.len

Copy link
Contributor

🐧 Linux bisect by @juancarlospaco (collaborator)
devel 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(6, 6) Error: expression 'heapqueue' has no type (or is ambiguous)
assertions.nim(34)       raiseAssert
Error: unhandled exception: errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-05-11T13:52:10
  • Finished 2024-05-11T13:52:11
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("heapqueue")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Algo"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("heapqueue"),
        newIdentNode("quick")
      )
    )
  ),
  nnkProcDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("bar")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("algo"),
        newEmptyNode(),
        newIdentNode("quick")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("x"),
          nnkBracketExpr.newTree(
            newIdentNode("HeapQueue"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkCaseStmt.newTree(
        newIdentNode("algo"),
        nnkOfBranch.newTree(
          newIdentNode("heapqueue"),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("echo"),
              newLit(1)
            )
          )
        ),
        nnkOfBranch.newTree(
          newIdentNode("quick"),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("echo"),
              newLit(2)
            )
          )
        )
      ),
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkDotExpr.newTree(
          newIdentNode("x"),
          newIdentNode("len")
        )
      )
    )
  )
)
stable 👍 OK

Output


IR

Compiled filesize 90.64 Kb (92,816 bytes)
#define NIM_INTBITS 64
#include "nimbase.h"
N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
#if 0
 void (*volatile inner)(void);
 inner = PreMainInner;
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 (*inner)();
#else
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 PreMainInner();
#endif
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
 NimMainModule();
}
N_CDECL(void, NimMain)(void) {
#if 0
 void (*volatile inner)(void);
 PreMain();
 inner = NimMainInner;
 (*inner)();
#else
 PreMain();
 NimMainInner();
#endif
}
int main(int argc, char** args, char** env) {
 cmdLine = args;
 cmdCount = argc;
 gEnv = env;
 NimMain();
 return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
 nimTestErrorFlag();
}
}

Stats

  • Started 2024-05-11T13:52:11
  • Finished 2024-05-11T13:52:12
  • Duration
2.0.4 👍 OK

Output


IR

Compiled filesize 90.64 Kb (92,816 bytes)
#define NIM_INTBITS 64
#include "nimbase.h"
N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
#if 0
 void (*volatile inner)(void);
 inner = PreMainInner;
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 (*inner)();
#else
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 PreMainInner();
#endif
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
 NimMainModule();
}
N_CDECL(void, NimMain)(void) {
#if 0
 void (*volatile inner)(void);
 PreMain();
 inner = NimMainInner;
 (*inner)();
#else
 PreMain();
 NimMainInner();
#endif
}
int main(int argc, char** args, char** env) {
 cmdLine = args;
 cmdCount = argc;
 gEnv = env;
 NimMain();
 return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
 nimTestErrorFlag();
}
}

Stats

  • Started 2024-05-11T13:52:12
  • Finished 2024-05-11T13:52:12
  • Duration
1.6.20 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(2, 18) Error: redefinition of 'heapqueue'; previous declaration here: /home/runner/work/Nim/Nim/temp.nim(1, 11)
fatal.nim(54)            sysFatal
Error: unhandled exception: options.nim(662, 14) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 90.64 Kb (92,816 bytes)
#define NIM_INTBITS 64
#include "nimbase.h"
N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
#if 0
 void (*volatile inner)(void);
 inner = PreMainInner;
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 (*inner)();
#else
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 PreMainInner();
#endif
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
 NimMainModule();
}
N_CDECL(void, NimMain)(void) {
#if 0
 void (*volatile inner)(void);
 PreMain();
 inner = NimMainInner;
 (*inner)();
#else
 PreMain();
 NimMainInner();
#endif
}
int main(int argc, char** args, char** env) {
 cmdLine = args;
 cmdCount = argc;
 gEnv = env;
 NimMain();
 return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
 nimTestErrorFlag();
}
}

Stats

  • Started 2024-05-11T13:52:15
  • Finished 2024-05-11T13:52:15
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("heapqueue")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Algo"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("heapqueue"),
        newIdentNode("quick")
      )
    )
  ),
  nnkProcDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("bar")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("algo"),
        newEmptyNode(),
        newIdentNode("quick")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("x"),
          nnkBracketExpr.newTree(
            newIdentNode("HeapQueue"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkCaseStmt.newTree(
        newIdentNode("algo"),
        nnkOfBranch.newTree(
          newIdentNode("heapqueue"),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("echo"),
              newLit(1)
            )
          )
        ),
        nnkOfBranch.newTree(
          newIdentNode("quick"),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("echo"),
              newLit(2)
            )
          )
        )
      ),
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkDotExpr.newTree(
          newIdentNode("x"),
          newIdentNode("len")
        )
      )
    )
  )
)
1.4.8 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(2, 18) Error: redefinition of 'heapqueue'; previous declaration here: /home/runner/.choosenim/toolchains/nim-1.4.8/lib/pure/collections/heapqueue.nim(1, 2)

IR

Compiled filesize 90.64 Kb (92,816 bytes)
#define NIM_INTBITS 64
#include "nimbase.h"
N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
#if 0
 void (*volatile inner)(void);
 inner = PreMainInner;
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 (*inner)();
#else
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 PreMainInner();
#endif
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
 NimMainModule();
}
N_CDECL(void, NimMain)(void) {
#if 0
 void (*volatile inner)(void);
 PreMain();
 inner = NimMainInner;
 (*inner)();
#else
 PreMain();
 NimMainInner();
#endif
}
int main(int argc, char** args, char** env) {
 cmdLine = args;
 cmdCount = argc;
 gEnv = env;
 NimMain();
 return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
 nimTestErrorFlag();
}
}

Stats

  • Started 2024-05-11T13:52:17
  • Finished 2024-05-11T13:52:18
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("heapqueue")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Algo"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("heapqueue"),
        newIdentNode("quick")
      )
    )
  ),
  nnkProcDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("bar")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("algo"),
        newEmptyNode(),
        newIdentNode("quick")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("x"),
          nnkBracketExpr.newTree(
            newIdentNode("HeapQueue"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkCaseStmt.newTree(
        newIdentNode("algo"),
        nnkOfBranch.newTree(
          newIdentNode("heapqueue"),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("echo"),
              newLit(1)
            )
          )
        ),
        nnkOfBranch.newTree(
          newIdentNode("quick"),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("echo"),
              newLit(2)
            )
          )
        )
      ),
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkDotExpr.newTree(
          newIdentNode("x"),
          newIdentNode("len")
        )
      )
    )
  )
)
1.2.18 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(2, 18) Error: redefinition of 'heapqueue'; previous declaration here: /home/runner/.choosenim/toolchains/nim-1.2.18/lib/pure/collections/heapqueue.nim(1, 2)

IR

Compiled filesize 90.64 Kb (92,816 bytes)
#define NIM_INTBITS 64
#include "nimbase.h"
N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
#if 0
 void (*volatile inner)(void);
 inner = PreMainInner;
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 (*inner)();
#else
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 PreMainInner();
#endif
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
 NimMainModule();
}
N_CDECL(void, NimMain)(void) {
#if 0
 void (*volatile inner)(void);
 PreMain();
 inner = NimMainInner;
 (*inner)();
#else
 PreMain();
 NimMainInner();
#endif
}
int main(int argc, char** args, char** env) {
 cmdLine = args;
 cmdCount = argc;
 gEnv = env;
 NimMain();
 return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
 nimTestErrorFlag();
}
}

Stats

  • Started 2024-05-11T13:52:20
  • Finished 2024-05-11T13:52:20
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("heapqueue")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Algo"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("heapqueue"),
        newIdentNode("quick")
      )
    )
  ),
  nnkProcDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("bar")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("algo"),
        newEmptyNode(),
        newIdentNode("quick")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("x"),
          nnkBracketExpr.newTree(
            newIdentNode("HeapQueue"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkCaseStmt.newTree(
        newIdentNode("algo"),
        nnkOfBranch.newTree(
          newIdentNode("heapqueue"),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("echo"),
              newLit(1)
            )
          )
        ),
        nnkOfBranch.newTree(
          newIdentNode("quick"),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("echo"),
              newLit(2)
            )
          )
        )
      ),
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkDotExpr.newTree(
          newIdentNode("x"),
          newIdentNode("len")
        )
      )
    )
  )
)
1.0.10 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(2, 18) Error: redefinition of 'heapqueue'; previous declaration here: /home/runner/.choosenim/toolchains/nim-1.0.10/lib/pure/collections/heapqueue.nim(1, 2)

IR

Compiled filesize 90.64 Kb (92,816 bytes)
#define NIM_INTBITS 64
#include "nimbase.h"
N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
#if 0
 void (*volatile inner)(void);
 inner = PreMainInner;
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 (*inner)();
#else
 atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot4atslibatssystemdotnim_Init000();
 PreMainInner();
#endif
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
 NimMainModule();
}
N_CDECL(void, NimMain)(void) {
#if 0
 void (*volatile inner)(void);
 PreMain();
 inner = NimMainInner;
 (*inner)();
#else
 PreMain();
 NimMainInner();
#endif
}
int main(int argc, char** args, char** env) {
 cmdLine = args;
 cmdCount = argc;
 gEnv = env;
 NimMain();
 return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
 nimTestErrorFlag();
}
}

Stats

  • Started 2024-05-11T13:52:22
  • Finished 2024-05-11T13:52:22
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("heapqueue")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Algo"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("heapqueue"),
        newIdentNode("quick")
      )
    )
  ),
  nnkProcDef.newTree(
    nnkPostfix.newTree(
      newIdentNode("*"),
      newIdentNode("bar")
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("algo"),
        newEmptyNode(),
        newIdentNode("quick")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("x"),
          nnkBracketExpr.newTree(
            newIdentNode("HeapQueue"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkCaseStmt.newTree(
        newIdentNode("algo"),
        nnkOfBranch.newTree(
          newIdentNode("heapqueue"),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("echo"),
              newLit(1)
            )
          )
        ),
        nnkOfBranch.newTree(
          newIdentNode("quick"),
          nnkStmtList.newTree(
            nnkCommand.newTree(
              newIdentNode("echo"),
              newLit(2)
            )
          )
        )
      ),
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkDotExpr.newTree(
          newIdentNode("x"),
          newIdentNode("len")
        )
      )
    )
  )
)
#c101490a0 ➡️ 🐛

Diagnostics

metagn introduced a bug at 2024-05-10 11:30:57 +0300 on commit #c101490a0 with message:

remove bad type inference behavior for enum identifiers (#23588)

refs
https://github.com/nim-lang/Nim/issues/23586#issuecomment-2102113750

In #20091 a bad kind of type inference was mistakenly left in where if
an identifier `abc` had an expected type of an enum type `Enum`, and
`Enum` had a member called `abc`, the identifier would change to be that
enum member. This causes bugs where a local symbol can have the same
name as an enum member but have a different value. I had assumed this
behavior was removed since but it wasn't, and CI seems to pass having it
removed.

A separate PR needs to be made for the 2.0 branch because these lines
were moved around during a refactoring in #23123 which is not in 2.0.

The bug is in the files:

compiler/semexprs.nim
tests/lookups/tenumlocalsym.nim

The bug can be in the commits:

(Diagnostics sometimes off-by-one).

Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.2
  • Created 2024-05-11T13:51:41Z
  • Comments 1
  • Commands nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 54 minutes bisecting 606 commits at 11 commits per second

@juancarlospaco
Copy link
Collaborator

@metagn See Bisect.

@metagn
Copy link
Collaborator

metagn commented May 11, 2024

Pre-existing in general:

import std/heapqueue
proc heapqueue(x: int) = discard
# or type Algo = enum heapqueue
let x = heapqueue

A non-pre-existing version would be:

import std/heapqueue
type Algo = enum heapqueue, quick
let x: Algo = heapqueue # note type annotation

We could disable module symbols in any context where a value is expected but in foo.bar the compiler expects foo to have a type. Maybe foo.bar should be a specific context where module symbols are allowed? But this could break code like:

macro foo(x: typed) = discard

import math
foo(math)

Something that has a better chance of working is not giving module symbols "priority" in symbol lookup (don't break in searchInScopesFilterBy) because they don't check for overloads so they would be treated as ambiguous and get resolved away but this isn't reliable because the order in which the symbols are imported/declared would affect it.

metagn added a commit to metagn/Nim that referenced this issue May 11, 2024
Araq pushed a commit that referenced this issue May 14, 2024
fixes #23596

When importing a module and declaring an overloadable symbol with the
same name as the module in the same scope, the module symbol can take
over and make the declared overload impossible to access. Previously
enum overloading had a quirk that bypassed this in a context where a
specific enum type was expected but this was removed in #23588. Now this
is bypassed in every place where a specific type is expected since
module symbols don't have a type and so wouldn't be compatible anyway.

But the issue still exists in places where no type is expected like `let
x = modulename`. I don't see a way of fixing this without nerfing module
symbols to the point where they're not accessible by default, which
might break some macro code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants