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

Postconditions specified more than once always cause compile error #5

Open
PeterBindels-TomTom opened this issue Oct 14, 2024 · 3 comments

Comments

@PeterBindels-TomTom
Copy link

PeterBindels-TomTom commented Oct 14, 2024

int f() post(r: r > 0);
int f() post(r: r > 0);

or even

#define F(X) X; X
F(int f() post(r: r > 0));

the compiler claims

<source>:7:5: error: function redeclaration differs in contract specifier sequence
    7 | int f() post(r: r > 0);
      |     ^   ~~~~~~~~~~~~~
<source>:7:9: note: in contract specified here
    7 | int f() post(r: r > 0);
      |         ^       ~~~~~
<source>:6:9: note: contract previously specified with a non-equivalent condition
    6 | int f() post(r: r > 0);
      |         ^       ~~~~~```

Contracts may be redeclared according to P2900 if they specify the same contract (https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2900r8.pdf page 68, quote "A declaration E of a function f that is not a first declaration shall have either no function-contract-specifier-seq or the same function-contract-specifier-seq as any first declaration D reachable from E.")

@EricWF
Copy link
Member

EricWF commented Oct 14, 2024

Yeah, so the bug here is that the compiler is seeing two different declarations of r and then assuming they're not equivalent because they're not the exact same declaration.

The fix is to compare them like parameters, which means checking the type and the function scope depth to establish equality. Fix incoming shortly.

@EricWF
Copy link
Member

EricWF commented Oct 14, 2024

A partial fix is in 00aafdc,

I think this current fix will accept things like that below

I think the below code is always invalid because you can't re declare a contract containing a lambda?

int f() post(r :  []() post(s : s > 0) { return r; }());
int f() post(r : []() post(s : r > 0) { return r; }()); 

@PeterBindels-TomTom
Copy link
Author

Yep, those lambdas are by definition never the same. Those without lambdas though should be fine.

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

No branches or pull requests

2 participants