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

Add a get_name implementation to BasicValue / BasicValueEnum #306

Closed
pejato opened this issue Feb 27, 2022 · 1 comment · Fixed by #469
Closed

Add a get_name implementation to BasicValue / BasicValueEnum #306

pejato opened this issue Feb 27, 2022 · 1 comment · Fixed by #469
Milestone

Comments

@pejato
Copy link

pejato commented Feb 27, 2022

Is your feature request related to a problem? Please describe.

Hi @TheDan64, I've been working through Kaleidoscope's tutorial with inkwell and realized that I couldn't simply grab a parameter's name. e.g. I wanted to do something like the below

let the_fn: FunctionValue = ...
...
for param in the_fn.get_param_iter() {
  // I want to use param.get_name() here!
  self.named_values.insert(param.get_name(), param.as_any_value_enum());
}

Because function parameter's should be float valued in Kaleidoscope, I can simply check the param type with is_float_value() and then cast it with into_float_value() if that check succeeds, then I can use FloatValue's get_name(). i.e.,

let param_as_float: FloatValue = if param.is_float_value() {
    Ok(param.into_float_value())
} else {
    Err( ... )
}?;

let param_name = param_as_float
    .get_name()
    .to_str()
    ...

So it seems you can work around it, it just doesn't feel as ergonomic.

Describe the solution you'd like
I haven't thought about solutions here. I did see an old thread where get_name() was mentioned, so thought I'd re-raise it since it's been a few years.

@TheDan64 TheDan64 added this to the 0.1.0 milestone Mar 2, 2022
@TheDan64
Copy link
Owner

TheDan64 commented Mar 2, 2022

If all possible BasicValueEnum variants support get_name, then I suppose this makes sense

@TheDan64 TheDan64 modified the milestones: 0.1.0, 0.2.0 Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants