Skip to content

Conversation

AntennaeVY
Copy link
Contributor

Fixes typechecking of instanceof operator only working on classes. Now working on primitive types and enums

Before these gave an error

1 instanceof int
x instanceof MyEnum

Now the typechecker should properly check these are valid

Copy link

vercel bot commented Oct 16, 2025

@AntennaeVY is attempting to deploy a commit to the Boundary Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

🔒 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() => {}

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.

Suggested change
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(_)))) => {}

@imalsogreg
Copy link
Contributor

Thanks for this! Typechecker side looks perfect! As discussed on Discord, we just need the interpreter side implemented, in order to merge this 🎉

@AntennaeVY AntennaeVY force-pushed the fix/instanceof-operator-on-primitives branch 2 times, most recently from 40ff877 to bf67e09 Compare October 17, 2025 02:09
@AntennaeVY AntennaeVY force-pushed the fix/instanceof-operator-on-primitives branch from bf67e09 to eca2759 Compare October 17, 2025 03:08
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.

2 participants