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

Proc returning var T breaks as typed macro argument #16137

Open
timotheecour opened this issue Nov 25, 2020 · 2 comments
Open

Proc returning var T breaks as typed macro argument #16137

timotheecour opened this issue Nov 25, 2020 · 2 comments
Labels

Comments

@timotheecour
Copy link
Member

timotheecour commented Nov 25, 2020

typed broken: macro fn(a: typed): untyped = a breaks code

Example

# macro fn(a: untyped): untyped = a # ok
macro fn(a: typed): untyped = a # bug
fn:
  proc bar(c: var int): var int = c

Current Output

t11372.nim(10, 35) Error: type mismatch:
 got <ptr int> [ptr]
 but expected 'int' [int declared in /Users/timothee/git_clone/nim/Nim_devel/lib/system/basic_types.nim(2, 3)]
    proc bar(c: var int): var int = c
                                    ^
/Users/timothee/git_clone/nim/Nim_devel/compiler/types.nim(1514, 15) compiler msg initiated here [MsgOrigin]

Expected Output

works

Additional Information

@metagn metagn added the Macros label Aug 28, 2023
@metagn metagn changed the title typed broken: macro fn(a: typed): untyped = a breaks code Proc returning var T breaks as typed macro argument Aug 28, 2023
@ringabout
Copy link
Member

!nim c

# macro fn(a: untyped): untyped = a # ok
macro fn(a: typed): untyped = a # bug
fn:
  proc bar(c: var int): var int = c

Copy link
Contributor

github-actions bot commented Feb 5, 2024

🐧 Linux bisect by @ringabout (member)
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(3, 1) template/generic instantiation of `fn` from here
/home/runner/work/Nim/Nim/temp.nim(4, 35) Error: type mismatch: got 'ptr int' for 'c' but expected 'int'
assertions.nim(34)       raiseAssert
Error: unhandled exception: errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-05T14:56:00
  • Finished 2024-02-05T14:56:00
  • Duration

AST

nnkStmtList.newTree(
  nnkMacroDef.newTree(
    newIdentNode("fn"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("a")
    )
  ),
  nnkCall.newTree(
    newIdentNode("fn"),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("bar"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          nnkVarTy.newTree(
            newIdentNode("int")
          ),
          nnkIdentDefs.newTree(
            newIdentNode("c"),
            nnkVarTy.newTree(
              newIdentNode("int")
            ),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          newIdentNode("c")
        )
      )
    )
  )
)
stable 👎 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(3, 1) template/generic instantiation of `fn` from here
/home/runner/work/Nim/Nim/temp.nim(4, 35) Error: type mismatch: got 'ptr int' for 'c' but expected 'int'
assertions.nim(34)       raiseAssert
Error: unhandled exception: options.nim(681, 5) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-05T14:56:01
  • Finished 2024-02-05T14:56:01
  • Duration

AST

nnkStmtList.newTree(
  nnkMacroDef.newTree(
    newIdentNode("fn"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("a")
    )
  ),
  nnkCall.newTree(
    newIdentNode("fn"),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("bar"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          nnkVarTy.newTree(
            newIdentNode("int")
          ),
          nnkIdentDefs.newTree(
            newIdentNode("c"),
            nnkVarTy.newTree(
              newIdentNode("int")
            ),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          newIdentNode("c")
        )
      )
    )
  )
)
2.0.0 👎 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(3, 1) template/generic instantiation of `fn` from here
/home/runner/work/Nim/Nim/temp.nim(4, 35) Error: type mismatch: got 'ptr int' for 'c' but expected 'int'
assertions.nim(34)       raiseAssert
Error: unhandled exception: options.nim(664, 5) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-05T14:56:05
  • Finished 2024-02-05T14:56:06
  • Duration

AST

nnkStmtList.newTree(
  nnkMacroDef.newTree(
    newIdentNode("fn"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("a")
    )
  ),
  nnkCall.newTree(
    newIdentNode("fn"),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("bar"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          nnkVarTy.newTree(
            newIdentNode("int")
          ),
          nnkIdentDefs.newTree(
            newIdentNode("c"),
            nnkVarTy.newTree(
              newIdentNode("int")
            ),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          newIdentNode("c")
        )
      )
    )
  )
)
1.6.14 👎 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(3, 1) template/generic instantiation of `fn` from here
/home/runner/work/Nim/Nim/temp.nim(4, 35) Error: type mismatch: got 'ptr int' for 'c' but expected 'int'
fatal.nim(54)            sysFatal
Error: unhandled exception: options.nim(645, 14) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-05T14:56:10
  • Finished 2024-02-05T14:56:10
  • Duration

AST

nnkStmtList.newTree(
  nnkMacroDef.newTree(
    newIdentNode("fn"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("a")
    )
  ),
  nnkCall.newTree(
    newIdentNode("fn"),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("bar"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          nnkVarTy.newTree(
            newIdentNode("int")
          ),
          nnkIdentDefs.newTree(
            newIdentNode("c"),
            nnkVarTy.newTree(
              newIdentNode("int")
            ),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          newIdentNode("c")
        )
      )
    )
  )
)
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(3, 1) template/generic instantiation of `fn` from here
/home/runner/work/Nim/Nim/temp.nim(4, 35) Error: type mismatch: got <ptr int> but expected 'int'

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-05T14:56:13
  • Finished 2024-02-05T14:56:13
  • Duration

AST

nnkStmtList.newTree(
  nnkMacroDef.newTree(
    newIdentNode("fn"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("typed"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("a")
    )
  ),
  nnkCall.newTree(
    newIdentNode("fn"),
    nnkStmtList.newTree(
      nnkProcDef.newTree(
        newIdentNode("bar"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          nnkVarTy.newTree(
            newIdentNode("int")
          ),
          nnkIdentDefs.newTree(
            newIdentNode("c"),
            nnkVarTy.newTree(
              newIdentNode("int")
            ),
            newEmptyNode()
          )
        ),
        newEmptyNode(),
        newEmptyNode(),
        nnkStmtList.newTree(
          newIdentNode("c")
        )
      )
    )
  )
)
1.2.18 👍 OK

Output


IR

Compiled filesize 86.88 Kb (88,968 bytes)
#define NIM_INTBITS 64
#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

  • Started 2024-02-05T14:56:15
  • Finished 2024-02-05T14:56:16
  • Duration
1.0.10 👍 OK

Output


IR

Compiled filesize 81.98 Kb (83,952 bytes)
#define NIM_INTBITS 64
#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

  • Started 2024-02-05T14:56:18
  • Finished 2024-02-05T14:56:18
  • Duration
#fb58066b6 ➡️ 🐛

Diagnostics

clyybber introduced a bug at 2020-08-27 15:50:59 +0200 on commit #fb58066b6 with message:

Fix #5691 (#15158)

* Fix #5691
* Cleanup and thoughts
* Use scope approach
* Seperate defined/declared/declaredInScope magics
* Fix declaredInScope
* Update spec accordingly

The bug is in the files:

compiler/ast.nim
compiler/condsyms.nim
compiler/lookups.nim
compiler/sem.nim
compiler/semcall.nim
compiler/semexprs.nim
compiler/semgnrc.nim
compiler/semstmts.nim
compiler/sigmatch.nim
doc/manual.rst
lib/system.nim
tests/macros/tmacros_various.nim
tests/macros/tmacrotypes.nim
tests/template/tparams_gensymed.nim
tests/template/tparamscope.nim

The bug can be in the commits:

(Diagnostics sometimes off-by-one).

Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 19.0
  • Created 2024-02-05T14:55:28Z
  • 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 10 minutes bisecting 4888 commits at 481 commits per second

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants