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

newruntime and unused generics: compiler crash #6755

Closed
mratsim opened this issue Nov 15, 2017 · 4 comments
Closed

newruntime and unused generics: compiler crash #6755

mratsim opened this issue Nov 15, 2017 · 4 comments

Comments

@mratsim
Copy link
Collaborator

mratsim commented Nov 15, 2017

Compile this with nim c --newruntime --d:newruntime

type CustSeq = object
  data: seq[int]


proc newCustSeq(len: Natural): CustSeq =
  result.data = newSeq[int](len)

when defined(newruntime):
  echo "Using Nim new runtime"

  proc `=sink`[T](a: var CustSeq, b: CustSeq) =
    echo "Value sinked"
    shallowCopy(a, b)

  proc `=move`[T](a, b: var CustSeq) =
    echo "Value moved"
    shallowCopy(a, b)


proc main() =
  let a = newCustSeq(10)
  let b = a
  echo b

main()
Error: internal error: (filename: ccgexprs.nim, line: 972)
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp c <file>

Removing the [T] to the sink and move solves the issue

@Yardanico
Copy link
Collaborator

Gives better error now:

Hint: used config file '/home/yardanico/Nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
injecting into
## generic ``$`` operator for tuples that is lifted from the components
## of `x`. Example:
##
## .. code-block:: nim
##   $(23, 45) == "(23, 45)"
##   $() == "()"
result = "("
var firstElement = true
if not firstElement: add(result, ", ")
add(result, "data")
add(result, ": ")
if isNil(x.data): add(result, "nil")
else: add(result, $x.data)
firstElement = false
add(result, ")")
injecting into
let a = newCustSeq(10)
let b = a
echo [b]
test.nim(21, 7) Error: internal error: '=sink' operator is generic

@Yardanico
Copy link
Collaborator

@mratsim now prints:

tata.nim(21, 7) Error: internal error: '=sink' operator is generic

@narimiran
Copy link
Member

Gives better error now:

Gives worse error now:

SIGSEGV: Illegal storage access. (Attempt to read from nil?)

@narimiran
Copy link
Member

Gives worse error now:

...and better once again:

Error: unhandled exception: ..../compiler/liftdestructors.nim(583, 12) `typ.typeInst != nil` [AssertionError]

@Araq Araq closed this as completed in 950f2d7 May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants