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

A few bugs related to static parameters #12713

Closed
Clyybber opened this issue Nov 23, 2019 · 1 comment · Fixed by #13976
Closed

A few bugs related to static parameters #12713

Clyybber opened this issue Nov 23, 2019 · 1 comment · Fixed by #13976

Comments

@Clyybber
Copy link
Contributor

Three variations of a bug related to static parameters (doesn't matter if proc is annotated with {.compileTime.} or not.

Variation 1

import unicode

type Cell = object
  c: Rune

proc test(c: static string) = discard #Remove this and it compiles
proc test(c: Cell) = discard

test Cell(c: runeAt(" ", 0))

fails with:

Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: muscii [Processing]
Hint: unicode [Processing]
/home/clyybber/builds/nim/compiler/nim.nim(106) nim
/home/clyybber/builds/nim/compiler/nim.nim(83) handleCmdLine
/home/clyybber/builds/nim/compiler/cmdlinehelper.nim(98) loadConfigsAndRunMainCommand
/home/clyybber/builds/nim/compiler/main.nim(188) mainCommand
/home/clyybber/builds/nim/compiler/main.nim(92) commandCompileToC
/home/clyybber/builds/nim/compiler/modules.nim(144) compileProject
/home/clyybber/builds/nim/compiler/modules.nim(85) compileModule
/home/clyybber/builds/nim/compiler/passes.nim(210) processModule
/home/clyybber/builds/nim/compiler/passes.nim(86) processTopLevelStmt
/home/clyybber/builds/nim/compiler/cgen.nim(1871) myProcess
/home/clyybber/builds/nim/compiler/ccgstmts.nim(1263) genStmts
/home/clyybber/builds/nim/compiler/ccgexprs.nim(2584) expr
/home/clyybber/builds/nim/compiler/ccgcalls.nim(572) genCall
/home/clyybber/builds/nim/compiler/ccgcalls.nim(194) genPrefixCall
/home/clyybber/builds/nim/compiler/ccgcalls.nim(177) genArg
/home/clyybber/builds/nim/compiler/cgen.nim(593) initLocExprSingleUse
/home/clyybber/builds/nim/compiler/ccgexprs.nim(2610) expr
/home/clyybber/builds/nim/compiler/ccgexprs.nim(1368) genObjConstr
/home/clyybber/builds/nim/compiler/ccgexprs.nim(768) lookupFieldAgain
/home/clyybber/builds/nim/lib/system/assertions.nim(27) failedAssertImpl
/home/clyybber/builds/nim/lib/system/assertions.nim(20) raiseAssert
/home/clyybber/builds/nim/lib/system/fatal.nim(39) sysFatal
Error: unhandled exception: /home/clyybber/builds/nim/compiler/ccgexprs.nim(768, 11) `ty.kind in {tyTuple, tyObject}`  [AssertionError]

Variation 2

type Cell = object
  c: int

proc test(c: static string) = discard #Remove this and it compiles
proc test(c: Cell) = discard

test Cell(c: 0)

fails with:

Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: muscii [Processing]
/home/clyybber/projects/tests/symbolbind/muscii.nim(7, 10) Error: cannot create null element for: (c: 0)

Variation 3

type Cell = object
  c: int

proc test(c: static string) = discard #Remove this and it compiles
proc test(c: Cell) = discard

test Cell()

fails with:

Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: muscii [Processing]
/home/clyybber/projects/tests/symbolbind/muscii.nim(4, 6) Hint: 'test' is declared but not used [XDeclaredButNotUsed]
CC: muscii.nim
Error: execution of an external compiler program 'gcc -c  -w   -I/home/clyybber/builds/nim/lib -I/home/clyybber/projects/tests/symbolbind -o /home/clyybber/.cache/nim/muscii_d/@mmuscii.nim.c.o /home/clyybber/.cache/nim/muscii_d/@mmuscii.nim.c' failed with exit code: 1

/home/clyybber/.cache/nim/muscii_d/@mmuscii.nim.c: In function 'NimMainModule':
/home/clyybber/.cache/nim/muscii_d/@mmuscii.nim.c:125:2: error: conversion to non-scalar type requested
  125 |  T1_ = (tyObject_Cell__kmBW6cD01IjfZ6f5JDLCcg)0;
      |  ^~~
/home/clyybber/.cache/nim/muscii_d/@mmuscii.nim.c:126:2: error: conversion to non-scalar type requested
  126 |  T1_ = (tyObject_Cell__kmBW6cD01IjfZ6f5JDLCcg)0;
      |  ^~~
/home/clyybber/.cache/nim/muscii_d/@mmuscii.nim.c:127:32: error: incompatible type for argument 1 of 'test__Kx3WzCWNc9cOf2APfVplmdA'
  127 |  test__Kx3WzCWNc9cOf2APfVplmdA(T1_);
      |                                ^~~
      |                                |
      |                                tyObject_Cell__kmBW6cD01IjfZ6f5JDLCcg {aka struct tyObject_Cell__kmBW6cD01IjfZ6f5JDLCcg}
/home/clyybber/.cache/nim/muscii_d/@mmuscii.nim.c:79:101: note: expected 'tyObject_Cell__beQ9ceLyDS5Mtemd0Wyf0Qw' {aka 'struct tyObject_Cell__beQ9ceLyDS5Mtemd0Wyf0Qw'} but argument is of type 'tyObject_Cell__kmBW6cD01IjfZ6f5JDLCcg' {aka 'struct tyObject_Cell__kmBW6cD01IjfZ6f5JDLCcg'}
   79 | N_LIB_PRIVATE N_NIMCALL(void, test__Kx3WzCWNc9cOf2APfVplmdA)(tyObject_Cell__beQ9ceLyDS5Mtemd0Wyf0Qw c) { nimfr_("test", "/home/clyybber/projects/tests/symbolbind/muscii.nim");
      |                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Expected Output

All three should compile I guess?

Additional Information

$ nim -v
Nim Compiler Version 1.1.1 (#devel)
@Clyybber
Copy link
Contributor Author

This is caused by https://github.com/nim-lang/Nim/blob/devel/compiler/sigmatch.nim#L2003, it incorrectly sets the type to static Cell even though its currently matching Cell against static string.

timotheecour added a commit to timotheecour/Nim that referenced this issue Apr 14, 2020
Araq pushed a commit that referenced this issue Apr 14, 2020
…12713 ; refs #13529 (#13976)

* fix #12864 static params were mutating arg types during sigmatch

* fix test

* fix StaticParam

* also fixes #12713; added test case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants