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

Assignment overload crashes the compiler when using tuples #6434

Closed
edubart opened this issue Sep 25, 2017 · 3 comments
Closed

Assignment overload crashes the compiler when using tuples #6434

edubart opened this issue Sep 25, 2017 · 3 comments

Comments

@edubart
Copy link
Contributor

edubart commented Sep 25, 2017

Test case

type
  Foo* = object
    boo: int

proc `=`(dest: var Foo, src: Foo) =
  debugEcho "assingment"

proc test(): auto =
  var a,b : Foo
  return (a, b)

var (a, b) = test()

It doesn't compile, nim crashes with:

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

Tested nim head and stable.

Is there a workaround? I do want to overload assignment operator and use tuples with it.

@edubart edubart changed the title Assingment overload crashes the compiler when using tuples Assignment overload crashes the compiler when using tuples Sep 25, 2017
@stisa
Copy link
Contributor

stisa commented Sep 25, 2017

var a,b:Foo
(a,b) = test()

This prints "assignment" 4 times ( I think I remember something about return a being translated to result = a; return result, that may be the reason ) but seems to work as a workaround.

Note that:

proc `=`(dest: var Foo, src: Foo) =
  debugEcho "assingment"
  dest = src

causes a stack overflow (because of recursively calling the assignment I guess?)

@genotrance
Copy link
Contributor

Original snippet doesn't crash anymore with #head.

@Araq
Copy link
Member

Araq commented Sep 14, 2018

Now works.

Araq added a commit that referenced this issue Sep 16, 2018
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

6 participants