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

implementation's when clause treats unknowns as true #8672

Open
sanderr opened this issue Jan 23, 2025 · 1 comment
Open

implementation's when clause treats unknowns as true #8672

sanderr opened this issue Jan 23, 2025 · 1 comment
Labels
bug Something isn't working compiler

Comments

@sanderr
Copy link
Contributor

sanderr commented Jan 23, 2025

The when clause for an implementation treats Unknown values as if they were true, i.e. it emits the implementation. This is not consistent with the behavior of if. Example model that illustrates both behaviors below.

entity A:
    string name
    bool condition
end
implement A using conditional when self.condition
implement A using always

implementation conditional for A:
    std::print(f"implementation triggered for {self.name}!")
end
implementation always for A:
    if self.condition:
        std::print(f"if body triggered for {self.name}!")
    end
end


unknown = std::get_env("THIS_ENV_VAR_DOES_NOT_EXIST")

A(name="true", condition=true)
A(name="false", condition=false)
A(name="unknown", condition=unknown)

The output is

implementation triggered for true!
implementation triggered for unknown!
if body triggered for true!
@sanderr sanderr added bug Something isn't working compiler labels Jan 23, 2025
@sanderr
Copy link
Contributor Author

sanderr commented Jan 23, 2025

Confirmed for iso 7.0.0 (and master at the time of writing). Have not tried for any versions older than that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler
Projects
None yet
Development

No branches or pull requests

1 participant