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

Variable and parameter identifier should not depend on the type #43

Open
titorau opened this issue Feb 18, 2025 · 1 comment
Open

Variable and parameter identifier should not depend on the type #43

titorau opened this issue Feb 18, 2025 · 1 comment

Comments

@titorau
Copy link

titorau commented Feb 18, 2025

Version
flatzinc 0.3.21

Use case
Get a parameter identifier.

Current behavior
I have to match the ParDeclItem over all types to get its id.

fn get_id(parameter: ParDeclItem) -> String {
    match parameter {
        ParDeclItem::Bool { id, bool: _ } => id,
        ParDeclItem::Int { id, int: _ } => id,
        ParDeclItem::Float { id, float: _ } => id,
        ParDeclItem::SetOfInt { id, set_literal: _ } => id,
        ParDeclItem::ArrayOfBool { ix: _, id, v: _ } => id,
        ParDeclItem::ArrayOfInt { ix: _, id, v: _ } => id,
        ParDeclItem::ArrayOfFloat { ix: _, id, v: _ } => id,
        ParDeclItem::ArrayOfSet { ix: _, id, v: _ } => id,
    }
}

Expected behavior
I can easily access the identifier via an attribute.

fn get_id(parameter: ParDeclItem) -> String {
    parameter.id
}

Remark
The problem is the same with for accessing a variable identifier (in VarDeclItem).

@sthiele
Copy link
Member

sthiele commented Feb 24, 2025

Hi @titorau, I refactored ParDeclItem and VarDeclItem. The changes are in the next branch, feel free to test them out if you like.

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