-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Comments
!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 |
🐧 Linux bisect by @juancarlospaco (collaborator)devel 👎 FAILOutput
IRCompiled filesize0 bytes (0 bytes)
Stats
ASTnnkStmtList.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 👍 OKOutput
IRCompiled filesize90.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
2.0.4 👍 OKOutput
IRCompiled filesize90.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
1.6.20 👎 FAILOutput
IRCompiled filesize90.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
ASTnnkStmtList.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 👎 FAILOutput
IRCompiled filesize90.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
ASTnnkStmtList.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 👎 FAILOutput
IRCompiled filesize90.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
ASTnnkStmtList.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 👎 FAILOutput
IRCompiled filesize90.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
ASTnnkStmtList.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 ➡️ 🐛Diagnosticsmetagn introduced a bug at
The bug is in the files:
The bug can be in the commits:
(Diagnostics sometimes off-by-one). Stats
🤖 Bug found in |
@metagn See Bisect. |
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 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 |
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.
Description
Nim Version
nim-devel c91b33a
Current Output
Expected Output
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.
The text was updated successfully, but these errors were encountered: