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

Unsupported constant type Ref(...) #1268

Closed
Patrick-6 opened this issue Dec 15, 2022 · 2 comments · Fixed by #1332
Closed

Unsupported constant type Ref(...) #1268

Patrick-6 opened this issue Dec 15, 2022 · 2 comments · Fixed by #1332

Comments

@Patrick-6
Copy link
Contributor

Logical Equality currently does not work for enums:

use prusti_contracts::*;

pub enum TestEnum {
    Nil,
}

#[ensures(TestEnum::Nil === TestEnum::Nil)]
fn test() {}

Error on === TestEnum::Nil:

[Prusti: unsupported feature]
unsupported constant type Ref(ReErased, bug::unsupported_enum_equality::TestEnum, Not)
@Aurel300 Aurel300 changed the title Logical Equality === does not work for enum Unsupported constant type Ref(...) Dec 15, 2022
@Aurel300
Copy link
Member

The issue arises when you use &Foo where Foo is a constant, such as an enum variant with no arguments. a === b desugars to snapshot_equality(&a, &b), hence the error here.

@jscissr
Copy link
Contributor

jscissr commented Jan 12, 2023

There is a workaround for this problem: You can write a pure function which returns the constant. This only works if the type is Copy.

#[pure]
// Work around Prusti limitation. ("unsupported constant type")
fn none<T: Copy>() -> Option<T> {
  None
}

#[requires(x === none())]
fn demo(x: Option<bool>) {}

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 a pull request may close this issue.

3 participants