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

Catch invalid variant object usage at compile time. #15205

Open
al6x opened this issue Aug 19, 2020 · 1 comment
Open

Catch invalid variant object usage at compile time. #15205

al6x opened this issue Aug 19, 2020 · 1 comment
Labels

Comments

@al6x
Copy link

al6x commented Aug 19, 2020

Summary

Improve compile time inspection and catch wrong usage of variant object at compile time.

Currently compiler fails to catch that bug and it causes runtime exception.

Additional Information

This code should fail at compile time, not runtime

type
  DocKind = enum
    text,
    todo
  
  Doc = object
    case kind: DocKind
    of text: 
      text: string
    of todo:
      todo: string
    
let doc = Doc(kind: text, text: "some doc")
echo doc.text
echo doc.todo # <= bug, should be caught at compile time
@a-mr
Copy link
Contributor

a-mr commented Oct 6, 2021

There is a ProveField warning for this (e.g. --warning:ProveField:on --warningAsError:ProveField). But it does not work very well, see e.g. #7882. In your case it is triggered on both doc.text and doc.todo :-(.

There is an RFC for it: nim-lang/RFCs#25

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