Skip to content

fix #14339 #14970

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

Closed
wants to merge 4 commits into from
Closed

fix #14339 #14970

wants to merge 4 commits into from

Conversation

ringabout
Copy link
Member

@ringabout ringabout commented Jul 12, 2020

ref: #14339

@Varriount
Copy link
Contributor

  • Why does this work?
  • Wouldn't a better solution be to change the implementation, or extend the VM? I don't think introducing functionality in the standard library that's solely meant to work around compiler issues is a good idea. One the issue is fixed (hopefully) the functionality becomes pointless.

@ringabout
Copy link
Member Author

ringabout commented Jul 13, 2020

The get in CritBitTree returns var T which somehow can't be used in VM.
So there are three solutions:

  1. Make a version of get which doesn't use var T as return type.
  2. Extend VM which is hard for me :)
  3. Make get return T which is a break change, namely change to proc []*[T](c: var CritBitTree[T], key: string): T {.inline.}.
proc `[]`*[T](c: var CritBitTree[T], key: string): var T 

I will try to find the reason which cause this problem.

@ringabout ringabout closed this Jul 13, 2020
@ringabout
Copy link
Member Author

It seems to be related to generics templates. Moving codes in templates to [] proc seems to work. I don't know how to deal with it.

# template get[T](c: CritBitTree[T], key: string): T =
#   let n = rawGet(c, key)
#   if n == nil:
#     when compiles($key):
#       raise newException(KeyError, "key not found: " & $key)
#     else:
#       raise newException(KeyError, "key not found")
#   n.val

proc `[]`*[T](c: var CritBitTree[T], key: string): var T {.inline.} =
  # get(c, key)
  let n = rawGet(c, key)
  if n == nil:
    when compiles($key):
      raise newException(KeyError, "key not found: " & $key)
    else:
      raise newException(KeyError, "key not found")
  result = n.val

@timotheecour
Copy link
Member

It seems to be related to generics templates.

no, see #14339 (comment)

(always minimize examples to maximum extent before jumping to conclusions / bugfixes ;-) )

@timotheecour
Copy link
Member

superseded by #16002 (which makes VM support this)

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

Successfully merging this pull request may close these issues.

3 participants