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

[bugfix] literals in template strings #1132

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

imalsogreg
Copy link
Contributor

@imalsogreg imalsogreg commented Nov 1, 2024

Important

Fixes handling of literals in template strings by updating type inference and test cases to correctly identify and evaluate literal values.

  • Behavior:
    • Update infer_const_type in expr.rs to return Type::Literal for Bool, String, and Number kinds.
    • Modify error messages in test_expr.rs and test_stmt.rs to reflect literal types in function argument errors.
  • Tests:
    • Update test_ifexpr, test_call_function, and test_output_format in test_expr.rs to check for Type::Literal.
    • Update if_else in test_stmt.rs to handle literal types in conditional expressions.

This description was created by Ellipsis for a2180b3. It will automatically update as commits are pushed.

Copy link

vercel bot commented Nov 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
baml ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 1, 2024 10:22pm

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested. Reviewed everything up to a2180b3 in 38 seconds

More details
  • Looked at 155 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_VKsK1T5XIpb7RRJN


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

minijinja::value::ValueKind::Bool => Type::Bool,
minijinja::value::ValueKind::String => Type::String,
minijinja::value::ValueKind::Bool => {
match bool::from_str(&v.to_string()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using bool::from_str on the stringified value of minijinja::value::Value is not ideal. Consider directly converting the Value to a boolean without string conversion.

Suggested change
match bool::from_str(&v.to_string()) {
match v.as_bool().unwrap_or(false) {

@@ -410,7 +417,12 @@
}
minijinja::value::ValueKind::Map => Type::Unknown,
// We don't handle these types
minijinja::value::ValueKind::Number => Type::Number,
minijinja::value::ValueKind::Number => {
match i64::from_str(&v.to_string()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using i64::from_str on the stringified value of minijinja::value::Value is not ideal. Consider directly converting the Value to an integer without string conversion.

Suggested change
match i64::from_str(&v.to_string()) {
match v.as_i64() {

@imalsogreg imalsogreg added this pull request to the merge queue Nov 1, 2024
Merged via the queue into canary with commit b8a221f Nov 1, 2024
10 checks passed
@imalsogreg imalsogreg deleted the greg/literals-in-template-strings branch November 1, 2024 22:28
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 this pull request may close these issues.

1 participant