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

Default valued generic proc parameter causes missing parameter in generated C code. #21258

Closed
yuanweixin opened this issue Jan 14, 2023 · 4 comments · Fixed by #24006
Closed

Comments

@yuanweixin
Copy link

yuanweixin commented Jan 14, 2023

Description

Code:

type
  Item*[T] = object
    pos*: int

proc initItem[T](p:int=10000) : Item[T] = 
    result = Item[T](p)

proc doit[T](x:Item[T], s:Item[T]=initItem) : string = 
    return $x.pos

let x = Item[string](pos:100)
echo doit(x)

Nim Version

Nim Compiler Version 1.6.8 [Linux: amd64]
Compiled at 2022-10-05
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: c9f46ca
active boot switches: -d:release

Current Output

Output:

vagrant@devvm:~/nimly$ nim c -r tests/nim_bug_repro.nim 
Hint: used config file '/home/vagrant/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/vagrant/Nim/config/config.nims' [Conf]
Hint: used config file '/home/vagrant/nimly/tests/config.nims' [Conf]
..................................................................
CC: ../../Nim/lib/system/io.nim
CC: ../../Nim/lib/system.nim
CC: nim_bug_repro.nim
/home/vagrant/.cache/nim/nim_bug_repro_d/@mnim_bug_repro.nim.c: In function ‘NimMainModule’:
/home/vagrant/.cache/nim/nim_bug_repro_d/@mnim_bug_repro.nim.c:169:62: error: expected expression before ‘)’ token
  169 |  T1_[0] = dollar___nim95bug95repro_25(x__nim95bug95repro_11, );
      |                                                              ^
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/home/vagrant/Nim/lib -I/home/vagrant/nimly/tests -o /home/vagrant/.cache/nim/nim_bug_repro_d/@mnim_bug_repro.nim.c.o /home/vagrant/.cache/nim/nim_bug_repro_d/@mnim_bug_repro.nim.c' failed with exit code: 1

Expected Output

I'd expect proc doit[T](x:Item[T], s:HashSet[T]=initHashSet) : string = to be either valid code or I should get a compile error.

I do get an error, but it shows up as a gcc error, complaining about a missing parameter in a call.

This feels very opaque and doesn't show me what is wrong. My expectation would have been for the Nim compiler to error out, not for it to show up as a gcc error.

Possible Solution

Could Nim compiler error out instead of gcc crapping out on generated code?

Additional Information

This came up in a project where I defined $ on a generic type, with a generic second parameter as HashSet[T]=initHashSet. In a unit test I got the error above. So it's not an academic question ;)

@juancarlospaco
Copy link
Collaborator

!nim c

type Item[T] = object
  a: int
proc initItem[T](p=10000): Item[T] = Item[T](p)
proc doit[T](x:Item[T], s:Item[T]=initItem): string = $x.a
let x = Item[int](a:100)
discard doit(x)

@github-actions
Copy link
Contributor

github-actions bot commented Jul 8, 2023

@juancarlospaco (contributor)

devel :-1: FAIL

Output

Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings: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/@mtemp.nim.c: In function ‘NimMainModule’:
/home/runner/work/Nim/Nim/@mtemp.nim.c:153:50: error: expected expression before ‘)’ token
  153 |         colontmpD_ = doit__temp_u15(x__temp_u14, );
      |                                                  ^
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I'/home/runner/.choosenim/toolchains/nim-#devel/lib' -I/home/runner/work/Nim/Nim -o /home/runner/work/Nim/Nim/@mtemp.nim.c.o /home/runner/work/Nim/Nim/@mtemp.nim.c' failed with exit code: 1



Stats

  • Created 2023-07-08T23:06:07Z
  • Started 2023-07-08T23:06:40
  • Finished 2023-07-08T23:06:40
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

IR

#define NIM_INTBITS 64
#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
#define nimfr_(proc, file) \
  TFrame FR_; \
  FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
  #define nimfrs_(proc, file, slots, length) \
    struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename;NI len;VarSlot s[slots];} FR_; \
    FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
  #define nimln_(n) \
    FR_.line = n;
  #define nimlf_(n, file) \
    FR_.line = n; FR_.filename = file;
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
typedef struct tyObject_Item__H419cwzytubuJJ8qvlHaLwA tyObject_Item__H419cwzytubuJJ8qvlHaLwA;
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
struct tyObject_Item__H419cwzytubuJJ8qvlHaLwA {
	NI a;
};
N_LIB_PRIVATE N_NIMCALL(NimStringV2, doit__temp_u15)(tyObject_Item__H419cwzytubuJJ8qvlHaLwA x_p0, tyObject_Item__H419cwzytubuJJ8qvlHaLwA s_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___systemZdollars_u8)(NI x_p0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
static N_INLINE(void, nimFrame)(TFrame* s_p0);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_u4483)(void);
static N_INLINE(void, popFrame)(void);
N_LIB_PRIVATE N_NOCONV(void, dealloc)(void* p_p0);
N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE NIM_CONST tyObject_Item__H419cwzytubuJJ8qvlHaLwA x__temp_u14 = {((NI)100)}
;
extern NIM_BOOL nimInErrorMode__system_u4265;
extern TFrame* framePtr__system_u3877;
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (NIM_BOOL*)0;
	result = (&nimInErrorMode__system_u4265);
	return result;
}
static N_INLINE(void, nimFrame)(TFrame* s_p0) {
	{
		if (!(framePtr__system_u3877 == ((TFrame*) NIM_NIL))) goto LA3_;
		(*s_p0).calldepth = ((NI16)0);
	}
	goto LA1_;
LA3_: ;
	{
		(*s_p0).calldepth = (NI16)((*framePtr__system_u3877).calldepth + ((NI16)1));
	}
LA1_: ;
	(*s_p0).prev = framePtr__system_u3877;
	framePtr__system_u3877 = s_p0;
	{
		if (!((*s_p0).calldepth == ((NI16)2000))) goto LA8_;
		callDepthLimitReached__system_u4483();
	}
LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
	framePtr__system_u3877 = (*framePtr__system_u3877).prev;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, doit__temp_u15)(tyObject_Item__H419cwzytubuJJ8qvlHaLwA x_p0, tyObject_Item__H419cwzytubuJJ8qvlHaLwA s_p1) {
	NimStringV2 result;
NIM_BOOL* nimErr_;
	nimfr_("doit", "/home/runner/work/Nim/Nim/temp.nim");
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	result = dollar___systemZdollars_u8(x_p0.a);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	popFrame();
	return result;
}
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;
	atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000();
	(*inner)();
#else
	atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_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) {
{
	NimStringV2 colontmpD_;
NIM_BOOL* nimErr_;
	nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
nimErr_ = nimErrorFlag();
	colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
	colontmpD_ = doit__temp_u15(x__temp_u14, );
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	(void)(colontmpD_);
	if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
 dealloc(colontmpD_.p);
}
	BeforeRet_: ;
	nimTestErrorFlag();
	popFrame();
}
}

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Item"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("a"),
            newIdentNode("int"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initItem"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Item"),
        newIdentNode("T")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("p"),
        newEmptyNode(),
        newLit(10000)
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("p")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("string"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("s"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("initItem")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("$"),
        nnkDotExpr.newTree(
          newIdentNode("x"),
          newIdentNode("a")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("int")
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("a"),
          newLit(100)
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("doit"),
      newIdentNode("x")
    )
  )
)
stable :-1: FAIL

Output

Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings: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/@mtemp.nim.c: In function ‘NimMainModule’:
/home/runner/work/Nim/Nim/@mtemp.nim.c:137:41: error: expected expression before ‘)’ token
  137 |         T1_ = doit__temp_15(x__temp_14, );
      |                                         ^
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/home/runner/.choosenim/toolchains/nim-1.6.14/lib -I/home/runner/work/Nim/Nim -o /home/runner/work/Nim/Nim/@mtemp.nim.c.o /home/runner/work/Nim/Nim/@mtemp.nim.c' failed with exit code: 1



Stats

  • Created 2023-07-08T23:06:07Z
  • Started 2023-07-08T23:06:41
  • Finished 2023-07-08T23:06:42
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

IR

#define NIM_INTBITS 64
#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
  #  define nimfr_(proc, file) \
      TFrame FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
  #  define nimfrs_(proc, file, slots, length) \
      struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; VarSlot s[slots];} FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
  #  define nimln_(n, file) \
      FR_.line = n; FR_.filename = file;
  typedef struct tyObject_Item__H419cwzytubuJJ8qvlHaLwA tyObject_Item__H419cwzytubuJJ8qvlHaLwA;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
struct tyObject_Item__H419cwzytubuJJ8qvlHaLwA {
NI a;
};
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, doit__temp_15)(tyObject_Item__H419cwzytubuJJ8qvlHaLwA x, tyObject_Item__H419cwzytubuJJ8qvlHaLwA s);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, dollar___systemZdollars_3)(NI x);
static N_INLINE(void, nimFrame)(TFrame* s);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_2997)(void);
static N_INLINE(void, popFrame)(void);
static N_INLINE(void, initStackBottomWith)(void* locals);
N_LIB_PRIVATE N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus1dot6dot14atslibatssystemdotnim_DatInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus1dot6dot14atslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE NIM_CONST tyObject_Item__H419cwzytubuJJ8qvlHaLwA x__temp_14 = {((NI) 100)}
;
extern TFrame* framePtr__system_2564;
extern TFrame* framePtr__system_2564;
extern TFrame* framePtr__system_2564;
extern TFrame* framePtr__system_2564;
extern TFrame* framePtr__system_2564;
extern TFrame* framePtr__system_2564;
static N_INLINE(void, nimFrame)(TFrame* s) {
	{
		if (!(framePtr__system_2564 == ((TFrame*) NIM_NIL))) goto LA3_;
		(*s).calldepth = ((NI16) 0);
	}
	goto LA1_;
	LA3_: ;
	{
		(*s).calldepth = (NI16)((*framePtr__system_2564).calldepth + ((NI16) 1));
	}
	LA1_: ;
	(*s).prev = framePtr__system_2564;
	framePtr__system_2564 = s;
	{
		if (!((*s).calldepth == ((NI16) 2000))) goto LA8_;
		callDepthLimitReached__system_2997();
	}
	LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
	framePtr__system_2564 = (*framePtr__system_2564).prev;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, doit__temp_15)(tyObject_Item__H419cwzytubuJJ8qvlHaLwA x, tyObject_Item__H419cwzytubuJJ8qvlHaLwA s) {
	NimStringDesc* result;
	nimfr_("doit", "/home/runner/work/Nim/Nim/temp.nim");
	result = NIM_NIL;
	result = dollar___systemZdollars_3(x.a);
	popFrame();
	return result;
}
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;
	atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus1dot6dot14atslibatssystemdotnim_DatInit000();
	initStackBottomWith((void *)&inner);
	atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus1dot6dot14atslibatssystemdotnim_Init000();
	(*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) {
{
	NimStringDesc* T1_;
	nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
	T1_ = NIM_NIL;
	T1_ = doit__temp_15(x__temp_14, );
	(void)(T1_);
	popFrame();
}
}

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Item"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("a"),
            newIdentNode("int"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initItem"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Item"),
        newIdentNode("T")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("p"),
        newEmptyNode(),
        newLit(10000)
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("p")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("string"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("s"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("initItem")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("$"),
        nnkDotExpr.newTree(
          newIdentNode("x"),
          newIdentNode("a")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("int")
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("a"),
          newLit(100)
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("doit"),
      newIdentNode("x")
    )
  )
)
1.6.0 :-1: FAIL

Output

Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings: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/@mtemp.nim.c: In function ‘NimMainModule’:
/home/runner/work/Nim/Nim/@mtemp.nim.c:137:39: error: expected expression before ‘)’ token
  137 |         T1_ = doit_temp_15(x_temp_14, );
      |                                       ^
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/home/runner/.choosenim/toolchains/nim-1.6.0/lib -I/home/runner/work/Nim/Nim -o /home/runner/work/Nim/Nim/@mtemp.nim.c.o /home/runner/work/Nim/Nim/@mtemp.nim.c' failed with exit code: 1



Stats

  • Created 2023-07-08T23:06:07Z
  • Started 2023-07-08T23:06:45
  • Finished 2023-07-08T23:06:46
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

IR

#define NIM_INTBITS 64
#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
  #  define nimfr_(proc, file) \
      TFrame FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
  #  define nimfrs_(proc, file, slots, length) \
      struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; VarSlot s[slots];} FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
  #  define nimln_(n, file) \
      FR_.line = n; FR_.filename = file;
  typedef struct tyObject_Item__zqgZX7PytdHwzAVQOKtg1A tyObject_Item__zqgZX7PytdHwzAVQOKtg1A;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
struct tyObject_Item__zqgZX7PytdHwzAVQOKtg1A {
NI a;
};
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, doit_temp_15)(tyObject_Item__zqgZX7PytdHwzAVQOKtg1A x, tyObject_Item__zqgZX7PytdHwzAVQOKtg1A s);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, dollar__systemZdollars_3)(NI x);
static N_INLINE(void, nimFrame)(TFrame* s);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached_system_2997)(void);
static N_INLINE(void, popFrame)(void);
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);
N_LIB_PRIVATE NIM_CONST tyObject_Item__zqgZX7PytdHwzAVQOKtg1A x_temp_14 = {((NI) 100)}
;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
static N_INLINE(void, nimFrame)(TFrame* s) {
	{
		if (!(framePtr_system_2564 == ((TFrame*) NIM_NIL))) goto LA3_;
		(*s).calldepth = ((NI16) 0);
	}
	goto LA1_;
	LA3_: ;
	{
		(*s).calldepth = (NI16)((*framePtr_system_2564).calldepth + ((NI16) 1));
	}
	LA1_: ;
	(*s).prev = framePtr_system_2564;
	framePtr_system_2564 = s;
	{
		if (!((*s).calldepth == ((NI16) 2000))) goto LA8_;
		callDepthLimitReached_system_2997();
	}
	LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
	framePtr_system_2564 = (*framePtr_system_2564).prev;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, doit_temp_15)(tyObject_Item__zqgZX7PytdHwzAVQOKtg1A x, tyObject_Item__zqgZX7PytdHwzAVQOKtg1A s) {
	NimStringDesc* result;
	nimfr_("doit", "/home/runner/work/Nim/Nim/temp.nim");
	result = (NimStringDesc*)0;
	result = dollar__systemZdollars_3(x.a);
	popFrame();
	return result;
}
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) {
{
	NimStringDesc* T1_;
	nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
	T1_ = (NimStringDesc*)0;
	T1_ = doit_temp_15(x_temp_14, );
	(void)(T1_);
	popFrame();
}
}

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Item"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("a"),
            newIdentNode("int"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initItem"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Item"),
        newIdentNode("T")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("p"),
        newEmptyNode(),
        newLit(10000)
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("p")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("string"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("s"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("initItem")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("$"),
        nnkDotExpr.newTree(
          newIdentNode("x"),
          newIdentNode("a")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("int")
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("a"),
          newLit(100)
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("doit"),
      newIdentNode("x")
    )
  )
)
1.4.0 :-1: FAIL

Output

Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings: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/@mtemp.nim.c: In function ‘NimMainModule’:
/home/runner/work/Nim/Nim/@mtemp.nim.c:153:74: error: expected expression before ‘)’ token
  153 |         T1_ = doit__xXX5gi9babk9b2MG9am5AWFEA(x__FnxVSC5bS7DK6G1Il7xEdA, );
      |                                                                          ^
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/home/runner/.choosenim/toolchains/nim-1.4.0/lib -I/home/runner/work/Nim/Nim -o /home/runner/work/Nim/Nim/@mtemp.nim.c.o /home/runner/work/Nim/Nim/@mtemp.nim.c' failed with exit code: 1



Stats

  • Created 2023-07-08T23:06:07Z
  • Started 2023-07-08T23:06:49
  • Finished 2023-07-08T23:06:50
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

IR

#define NIM_INTBITS 64

#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix

  #  define nimfr_(proc, file) \
      TFrame FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
  #  define nimfrs_(proc, file, slots, length) \
      struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; VarSlot s[slots];} FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
  #  define nimln_(n, file) \
      FR_.line = n; FR_.filename = file;

typedef struct tyObject_Item__zqgZX7PytdHwzAVQOKtg1A tyObject_Item__zqgZX7PytdHwzAVQOKtg1A;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;

struct tyObject_Item__zqgZX7PytdHwzAVQOKtg1A {
NI a;
};
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};

N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, doit__xXX5gi9babk9b2MG9am5AWFEA)(tyObject_Item__zqgZX7PytdHwzAVQOKtg1A x, tyObject_Item__zqgZX7PytdHwzAVQOKtg1A s);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x);
static N_INLINE(void, nimFrame)(TFrame* s);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw)(void);
static N_INLINE(void, popFrame)(void);
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);

N_LIB_PRIVATE NIM_CONST tyObject_Item__zqgZX7PytdHwzAVQOKtg1A x__FnxVSC5bS7DK6G1Il7xEdA = {((NI) 100)}
;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;

static N_INLINE(void, nimFrame)(TFrame* s) {
	{
		if (!(framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw == NIM_NIL)) goto LA3_;
		(*s).calldepth = ((NI16) 0);
	}
	goto LA1_;
	LA3_: ;
	{
		(*s).calldepth = (NI16)((*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).calldepth + ((NI16) 1));
	}
	LA1_: ;
	(*s).prev = framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
	framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = s;
	{
		if (!((*s).calldepth == ((NI16) 2000))) goto LA8_;
		callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw();
	}
	LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
	framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = (*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).prev;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, doit__xXX5gi9babk9b2MG9am5AWFEA)(tyObject_Item__zqgZX7PytdHwzAVQOKtg1A x, tyObject_Item__zqgZX7PytdHwzAVQOKtg1A s) {
	NimStringDesc* result;
	nimfr_("doit", "/home/runner/work/Nim/Nim/temp.nim");
	result = (NimStringDesc*)0;
	result = nimIntToStr(x.a);
	popFrame();
	return result;
}
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) {
{
	NimStringDesc* T1_;
	nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
	T1_ = (NimStringDesc*)0;
	T1_ = doit__xXX5gi9babk9b2MG9am5AWFEA(x__FnxVSC5bS7DK6G1Il7xEdA, );
	(void)(T1_);
	popFrame();
}
}

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Item"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("a"),
            newIdentNode("int"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initItem"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Item"),
        newIdentNode("T")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("p"),
        newEmptyNode(),
        newLit(10000)
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("p")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("string"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("s"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("initItem")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("$"),
        nnkDotExpr.newTree(
          newIdentNode("x"),
          newIdentNode("a")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("int")
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("a"),
          newLit(100)
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("doit"),
      newIdentNode("x")
    )
  )
)
1.2.0 :-1: FAIL

Output

Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings: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/@mtemp.nim.c: In function ‘NimMainModule’:
/home/runner/work/Nim/Nim/@mtemp.nim.c:139:73: error: expected expression before ‘)’ token
  139 |         T1_ = doit__hvQxJ9b2j09a0mG8br7PrGew(x__FnxVSC5bS7DK6G1Il7xEdA, );
      |                                                                         ^
Error: execution of an external compiler program 'gcc -c  -w   -I/home/runner/.choosenim/toolchains/nim-1.2.0/lib -I/home/runner/work/Nim/Nim -o /home/runner/work/Nim/Nim/@mtemp.nim.c.o /home/runner/work/Nim/Nim/@mtemp.nim.c' failed with exit code: 1



Stats

  • Created 2023-07-08T23:06:07Z
  • Started 2023-07-08T23:07:06
  • Finished 2023-07-08T23:07:06
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

IR

#define NIM_INTBITS 64
#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
  #  define nimfr_(proc, file) \
      TFrame FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
  #  define nimfrs_(proc, file, slots, length) \
      struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; VarSlot s[slots];} FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
  #  define nimln_(n, file) \
      FR_.line = n; FR_.filename = file;
  typedef struct tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
struct tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA {
NI a;
};
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, doit__hvQxJ9b2j09a0mG8br7PrGew)(tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA x, tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA s);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x);
static N_INLINE(void, nimFrame)(TFrame* s);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw)(void);
static N_INLINE(void, popFrame)(void);
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);
N_LIB_PRIVATE NIM_CONST tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA x__FnxVSC5bS7DK6G1Il7xEdA = {((NI) 100)}
;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
static N_INLINE(void, nimFrame)(TFrame* s) {
	{
		if (!(framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw == NIM_NIL)) goto LA3_;
		(*s).calldepth = ((NI16) 0);
	}
	goto LA1_;
	LA3_: ;
	{
		(*s).calldepth = (NI16)((*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).calldepth + ((NI16) 1));
	}
	LA1_: ;
	(*s).prev = framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
	framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = s;
	{
		if (!((*s).calldepth == ((NI16) (((NI) 2000))))) goto LA8_;
		callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw();
	}
	LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
	framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = (*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).prev;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, doit__hvQxJ9b2j09a0mG8br7PrGew)(tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA x, tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA s) {
	NimStringDesc* result;
	nimfr_("doit", "/home/runner/work/Nim/Nim/temp.nim");
	result = (NimStringDesc*)0;
	result = nimIntToStr(x.a);
	popFrame();
	return result;
}
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) {
{
	NimStringDesc* T1_;
	nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
	T1_ = (NimStringDesc*)0;
	T1_ = doit__hvQxJ9b2j09a0mG8br7PrGew(x__FnxVSC5bS7DK6G1Il7xEdA, );
	(void)(T1_);
	popFrame();
}
}

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Item"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("a"),
            newIdentNode("int"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initItem"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Item"),
        newIdentNode("T")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("p"),
        newEmptyNode(),
        newLit(10000)
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("p")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("string"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("s"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("initItem")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("$"),
        nnkDotExpr.newTree(
          newIdentNode("x"),
          newIdentNode("a")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("int")
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("a"),
          newLit(100)
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("doit"),
      newIdentNode("x")
    )
  )
)
1.0.0 :-1: FAIL

Output

Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off  --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
Error: execution of an external compiler program 'gcc -c  -w  -I/home/runner/.choosenim/toolchains/nim-1.0.0/lib -I/home/runner/work/Nim/Nim -o /home/runner/work/Nim/Nim/@mtemp.nim.c.o /home/runner/work/Nim/Nim/@mtemp.nim.c' failed with exit code: 1

/home/runner/work/Nim/Nim/@mtemp.nim.c: In function ‘NimMainModule’:
/home/runner/work/Nim/Nim/@mtemp.nim.c:162:73: error: expected expression before ‘)’ token
  162 |         T1_ = doit__hvQxJ9b2j09a0mG8br7PrGew(x__FnxVSC5bS7DK6G1Il7xEdA, );
      |                                                                         ^

Stats

  • Created 2023-07-08T23:06:07Z
  • Started 2023-07-08T23:07:19
  • Finished 2023-07-08T23:07:19
  • Duration now
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

IR

#define NIM_INTBITS 64
#include "nimbase.h"
#include <string.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
  #  define nimfr_(proc, file) \
      TFrame FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
  #  define nimfrs_(proc, file, slots, length) \
      struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; VarSlot s[slots];} FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
  #  define nimln_(n, file) \
      FR_.line = n; FR_.filename = file;
  typedef struct tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
struct tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA {
NI a;
};
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
N_NOINLINE(void, chckNil)(void* p);
static N_INLINE(void, nimZeroMem)(void* p, NI size);
static N_INLINE(void, nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory)(void* a, int v, NI size);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, doit__hvQxJ9b2j09a0mG8br7PrGew)(tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA x, tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA s);
N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x);
static N_INLINE(void, nimFrame)(TFrame* s);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw)(void);
static N_INLINE(void, popFrame)(void);
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);
tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA x__FnxVSC5bS7DK6G1Il7xEdA;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
static N_INLINE(void, nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory)(void* a, int v, NI size) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memset(a, v, ((size_t) (size)));
}
static N_INLINE(void, nimZeroMem)(void* p, NI size) {
	nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory(p, ((int) 0), size);
}
static N_INLINE(void, nimFrame)(TFrame* s) {
	NI T1_;
	T1_ = (NI)0;
	{
		if (!(framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw == NIM_NIL)) goto LA4_;
		T1_ = ((NI) 0);
	}
	goto LA2_;
	LA4_: ;
	{
		T1_ = ((NI) ((NI16)((*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).calldepth + ((NI16) 1))));
	}
	LA2_: ;
	(*s).calldepth = ((NI16) (T1_));
	(*s).prev = framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
	framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = s;
	{
		if (!((*s).calldepth == ((NI16) (((NI) 2000))))) goto LA9_;
		callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw();
	}
	LA9_: ;
}
static N_INLINE(void, popFrame)(void) {
	framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = (*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).prev;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, doit__hvQxJ9b2j09a0mG8br7PrGew)(tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA x, tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA s) {
	NimStringDesc* result;
	nimfr_("doit", "/home/runner/work/Nim/Nim/temp.nim");
	result = (NimStringDesc*)0;
	result = nimIntToStr(x.a);
	popFrame();
	return result;
}
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) {
{
	NimStringDesc* T1_;
	nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
	chckNil((void*)(&x__FnxVSC5bS7DK6G1Il7xEdA));
	nimZeroMem((void*)(&x__FnxVSC5bS7DK6G1Il7xEdA), sizeof(tyObject_Item__WOSegQZ0Dp7yGjGbb9bHzpA));
	x__FnxVSC5bS7DK6G1Il7xEdA.a = ((NI) 100);
	T1_ = (NimStringDesc*)0;
	T1_ = doit__hvQxJ9b2j09a0mG8br7PrGew(x__FnxVSC5bS7DK6G1Il7xEdA, );
	(void)(T1_);
	popFrame();
}
}

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Item"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("a"),
            newIdentNode("int"),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("initItem"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Item"),
        newIdentNode("T")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("p"),
        newEmptyNode(),
        newLit(10000)
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("p")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("string"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("s"),
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("T")
        ),
        newIdentNode("initItem")
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("$"),
        nnkDotExpr.newTree(
          newIdentNode("x"),
          newIdentNode("a")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        nnkBracketExpr.newTree(
          newIdentNode("Item"),
          newIdentNode("int")
        ),
        nnkExprColonExpr.newTree(
          newIdentNode("a"),
          newLit(100)
        )
      )
    )
  ),
  nnkDiscardStmt.newTree(
    nnkCall.newTree(
      newIdentNode("doit"),
      newIdentNode("x")
    )
  )
)
🤖 Bug found in 43 minutes bisecting 6 commits at 0 commits per second.

@AmjadHD
Copy link
Contributor

AmjadHD commented Aug 23, 2024

The problem is caused when the default value's type doesn't match the parameter's declared type which is the case here.
(a proc passed to a parameter of type Item[T]).
Here's another repro:

proc foo*[T](x: seq[T], y: T = "foo") =
  discard

foo @[1, 2, 3]

@metagn
Copy link
Collaborator

metagn commented Aug 23, 2024

The compiler notices this and sets an error node but the error node doesn't actually error.

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.

4 participants