From 98a726215f322bb1d7cee91f761ea3b286b05bce Mon Sep 17 00:00:00 2001 From: AntennaeVY Date: Tue, 14 Oct 2025 22:31:51 -0400 Subject: [PATCH 1/2] feat(vscode): add debug configuration for baml-cli and build task --- .vscode/launch.json | 11 +++++++++++ .vscode/tasks.json | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index 99b7b73cf8..f33c3f49fd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -66,6 +66,17 @@ "outFiles": [ "${workspaceFolder}/typescript/apps/vscode-ext/dist/__test__/**/*.js" ] + }, + { + "name": "Debug baml-cli --check (direct)", + "type": "lldb", + "request": "launch", + "program": "${workspaceFolder}/engine/target/debug/baml-cli", + "args": ["check", "--from", "../integ-tests/"], + "cwd": "${workspaceFolder}/engine", + "env": { "RUST_LOG": "baml_cli=debug" }, + "preLaunchTask": "build baml-cli", + "sourceLanguages": ["rust"] } ], "compounds": [ diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 05773b3f74..06bd75669e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -77,6 +77,14 @@ "endsPattern": "." } } + }, + { + "label": "build baml-cli", + "type": "shell", + "command": "cargo", + "args": ["build", "--bin", "baml-cli"], + "options": { "cwd": "${workspaceFolder}/engine" }, + "problemMatcher": ["$rustc"] } ], "inputs": [ From eca275943bc9fe7cf3367fc477081e4bdee3064f Mon Sep 17 00:00:00 2001 From: AntennaeVY Date: Tue, 14 Oct 2025 22:32:48 -0400 Subject: [PATCH 2/2] feat(typecheck): enhance instanceof type checking with support for primitive types and enums --- engine/baml-compiler/src/thir/typecheck.rs | 13 ++++++++++--- .../baml_src/test-files/vm/expr_funcs.baml | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/engine/baml-compiler/src/thir/typecheck.rs b/engine/baml-compiler/src/thir/typecheck.rs index fb3a747237..3a819ac8fb 100644 --- a/engine/baml-compiler/src/thir/typecheck.rs +++ b/engine/baml-compiler/src/thir/typecheck.rs @@ -17,12 +17,13 @@ /// /// However, the current implementation is simple and ad-hoc, likely wrong /// in several places. Bidirectional typing is the target. -use std::{borrow::Cow, sync::Arc}; +use std::{borrow::Cow, str::FromStr, sync::Arc}; use baml_types::{ ir_type::{ArrowGeneric, TypeIR}, BamlMap, BamlMediaType, BamlValueWithMeta, TypeValue, }; +use baml_vm::types::Type; use internal_baml_ast::ast::WithSpan; use internal_baml_diagnostics::{DatamodelError, Diagnostics, Span}; @@ -1371,6 +1372,7 @@ pub fn typecheck_expression( "image" | "audio" | "video" | "pdf" | "baml" => {} cls if context.classes.contains_key(cls) => {} + p if TypeValue::from_str(p).is_ok() => {} _ => { diagnostics.push_error(DatamodelError::new_validation_error( @@ -2487,9 +2489,14 @@ pub fn typecheck_expression( thir::Expr::Var(name, _) => { if context.classes.get(name).is_some() { Some(TypeIR::bool()) + } else if context.enums.get(name).is_some() { + Some(TypeIR::bool()) + } else if TypeValue::from_str(name).is_ok() { + Some(TypeIR::bool()) } else { + // TODO: Check type aliases (may be recursive) diagnostics.push_error(DatamodelError::new_validation_error( - &format!("Class {name} not found"), + &format!("Type {name} not found"), span.clone(), )); None @@ -2497,7 +2504,7 @@ pub fn typecheck_expression( } _ => { diagnostics.push_error(DatamodelError::new_validation_error( - "Invalid binary operation (instanceof): right operand must be a class", + "Invalid binary operation (instanceof): right operand must be a type", span.clone(), )); None diff --git a/integ-tests/baml_src/test-files/vm/expr_funcs.baml b/integ-tests/baml_src/test-files/vm/expr_funcs.baml index edc592e422..946f77eec5 100644 --- a/integ-tests/baml_src/test-files/vm/expr_funcs.baml +++ b/integ-tests/baml_src/test-files/vm/expr_funcs.baml @@ -154,6 +154,12 @@ class DummyJsonTodo { userId int } +enum DummyEnum { + POSITIVE + NEGATIVE + NEUTRAL +} + function ExecFetchAs(url: string) -> DummyJsonTodo { let todo = baml.fetch_as(url); @@ -165,3 +171,15 @@ test Fib5() { args { n 5 } @@assert( {{ this == 5 }} ) } + +function InstanceofWithPrimitives(n: int) -> bool { + n instanceof int +} + +function InstanceofWithClasses(dummy: DummyJsonTodo) -> bool { + dummy instanceof DummyJsonTodo +} + +function InstanceofWithEnums(e: DummyEnum) -> bool { + e instanceof DummyEnum +}