-
Notifications
You must be signed in to change notification settings - Fork 309
Fix/instanceof operator on primitives #2618
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
base: canary
Are you sure you want to change the base?
Fix/instanceof operator on primitives #2618
Conversation
@AntennaeVY is attempting to deploy a commit to the Boundary Team on Vercel. A member of the Team first needs to authorize it. |
🔒 Entelligence AI Vulnerability Scanner ✅ No security vulnerabilities found! Your code passed our comprehensive security analysis. |
"image" | "audio" | "video" | "pdf" | "baml" => {} | ||
|
||
cls if context.classes.contains_key(cls) => {} | ||
p if TypeValue::from_str(p).is_ok() => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correctness: TypeValue::from_str(p).is_ok()
accepts any string that parses as a primitive or enum, but does not check if the type is actually defined in the current context, potentially allowing invalid types to pass silently.
🤖 AI Agent Prompt for Cursor/Windsurf
📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue
In engine/baml-compiler/src/thir/typecheck.rs, line 1360, the current check `TypeValue::from_str(p).is_ok()` allows any string that parses as a primitive or enum, even if the type is not defined in the current context. Update this line to only allow primitive types or enums that are actually defined in `context.enums` or are valid primitives. Replace the line with: `p if TypeValue::from_str(p).is_ok() && (context.enums.contains_key(p) || matches!(TypeValue::from_str(p), Ok(TypeValue::Primitive(_)))) => {}`.
📝 Committable Code Suggestion
‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.
p if TypeValue::from_str(p).is_ok() => {} | |
p if TypeValue::from_str(p).is_ok() && (context.enums.contains_key(p) || matches!(TypeValue::from_str(p), Ok(TypeValue::Primitive(_)))) => {} |
Thanks for this! Typechecker side looks perfect! As discussed on Discord, we just need the interpreter side implemented, in order to merge this 🎉 |
40ff877
to
bf67e09
Compare
bf67e09
to
eca2759
Compare
Fixes typechecking of
instanceof
operator only working on classes. Now working on primitive types and enumsBefore these gave an error
Now the typechecker should properly check these are valid