-
-
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
With const c: cstring
using literal string
value from template
, Error: type mismatch: got 'cstring' for '""' but expected 'string'
#24296
Comments
It is also a 1.6.12 -> 1.6.14 regression |
!nim c # Either changing the template to `proc`/`func` or using `$""`, not a string
# literal alone, allows any version of Nim 2.x to compile this.
template g(): string = ""
# But this does not compile across Nim 2.x/devel.
const c: cstring = g() |
🐧 Linux bisect by @ringabout (member)devel 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkTemplateDef.newTree(
newIdentNode("g"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("string")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
newLit("")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("c"),
newIdentNode("cstring"),
nnkCall.newTree(
newIdentNode("g")
)
)
)
) stable 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkTemplateDef.newTree(
newIdentNode("g"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("string")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
newLit("")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("c"),
newIdentNode("cstring"),
nnkCall.newTree(
newIdentNode("g")
)
)
)
) 2.0.10 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkTemplateDef.newTree(
newIdentNode("g"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("string")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
newLit("")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("c"),
newIdentNode("cstring"),
nnkCall.newTree(
newIdentNode("g")
)
)
)
) 2.0.0 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkTemplateDef.newTree(
newIdentNode("g"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("string")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
newLit("")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("c"),
newIdentNode("cstring"),
nnkCall.newTree(
newIdentNode("g")
)
)
)
) 1.6.20 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkTemplateDef.newTree(
newIdentNode("g"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("string")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
newLit("")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("c"),
newIdentNode("cstring"),
nnkCall.newTree(
newIdentNode("g")
)
)
)
) 1.4.8 👍 OKOutput
IRCompiled filesize91.16 Kb (93,344 bytes)
#include "nimbase.h"
#define nimfr_(x, y)
#define nimln_(x, y)
static N_INLINE(void, initStackBottomWith)(void* locals);
N_LIB_PRIVATE N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom);
N_LIB_PRIVATE N_NIMCALL(void, systemDatInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
static N_INLINE(void, initStackBottomWith)(void* locals) {
nimGC_setStackBottom(locals);
}
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) {
void (*volatile inner)(void);
inner = PreMainInner;
systemDatInit000();
initStackBottomWith((void *)&inner);
systemInit000();
(*inner)();
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
NimMainModule();
}
N_CDECL(void, NimMain)(void) {
void (*volatile inner)(void);
PreMain();
inner = NimMainInner;
initStackBottomWith((void *)&inner);
(*inner)();
}
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) {
{
}
} Stats
1.2.18 👍 OKOutput
IRCompiled filesize86.88 Kb (88,968 bytes)
#include "nimbase.h"
#define nimfr_(x, y)
#define nimln_(x, y)
static N_INLINE(void, initStackBottomWith)(void* locals);
N_LIB_PRIVATE N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom);
N_LIB_PRIVATE N_NIMCALL(void, systemDatInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
static N_INLINE(void, initStackBottomWith)(void* locals) {
nimGC_setStackBottom(locals);
}
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) {
void (*volatile inner)(void);
inner = PreMainInner;
systemDatInit000();
initStackBottomWith((void *)&inner);
systemInit000();
(*inner)();
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
NimMainModule();
}
N_CDECL(void, NimMain)(void) {
void (*volatile inner)(void);
PreMain();
inner = NimMainInner;
initStackBottomWith((void *)&inner);
(*inner)();
}
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) {
{
}
} Stats
1.0.10 👍 OKOutput
IRCompiled filesize81.98 Kb (83,952 bytes)
#include "nimbase.h"
#define nimfr_(x, y)
#define nimln_(x, y)
static N_INLINE(void, initStackBottomWith)(void* locals);
N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom);
N_LIB_PRIVATE N_NIMCALL(void, systemDatInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
static N_INLINE(void, initStackBottomWith)(void* locals) { nimGC_setStackBottom(locals);
}
void PreMainInner(void) {
}
int cmdCount;
char** cmdLine;
char** gEnv;
void PreMain(void) {
void (*volatile inner)(void);
inner = PreMainInner;
systemDatInit000();
initStackBottomWith((void *)&inner);
systemInit000();
(*inner)();
}
N_CDECL(void, NimMainInner)(void) {
NimMainModule();
}
N_CDECL(void, NimMain)(void) {
void (*volatile inner)(void);
PreMain();
inner = NimMainInner;
initStackBottomWith((void *)&inner);
(*inner)();
}
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) {
{
}
} Stats
#0014b9c48 ➡️ 🐛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 |
narimiran
pushed a commit
that referenced
this issue
Oct 23, 2024
#24298) fixes #24296 fixes #24295 Templates use `expectedType` for type inference. It's justified that when templates don't have an actual return type, i.e., `untyped` etc. When the return type of templates is specified, we should not infer the type ```nim template g(): string = "" let c: cstring = g() ``` In this example, it is not reasonable to annotate the templates expression with the `cstring` type before the `fitNode` check with its specified return type. (cherry picked from commit 80e6b35)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Nim Version
Current Output
Expected Output
Known Workarounds
No response
Additional Information
Related to #24295 but the method syntax usage seems to have accidentally worked around this through 2.0, until 2.2 (even giving the template a dummy parameter works in 2.0):
works in 2.0 but not 2.2/devel; see linked issue for more.
This issue points to a broader case which also did not work in 2.0.x.
The text was updated successfully, but these errors were encountered: