Skip to content

Commit 2ca4684

Browse files
sxlijinclaude
andcommitted
generics: more inference coverage, native TypeError, class-method must-specify, deep unbound recursion
Tests (bex + python): - heterogeneous array element unification (elem_type) - unbound-instance forcing-formal recovery (ContainerShapes, GenericRecursive, nested GenericPair) — now incl. FULLY-unbound deep nesting - concrete baml_sdk types in covariant joins (enum + class) - partial _types= noted as unusual; prefer inference / subscript Inference errors -> native TypeError: - route EngineError::TypeMismatch to a structured baml.errors.TypeMismatch (bridge_cffi) instead of an opaque SdkPanic; map to Python TypeError in proto.py; assert type + message on every must-specify / conflict case - add baml.errors.TypeMismatch stdlib class; refresh builtin/HIR/TIR/bytecode snapshots Class-method must-specify (rule 3): - carry generic_param_count on the runtime Class; Gate A demands a method's OWN generic params (suffix after the class prefix), so a body-only own var (reflect_t<T>()) is rejected, matching the free-function analogue Deep unbound recursion: - reconstruct_unbound_instance_args is formal-aware, recursing through nested unbound instances so all vars are recovered from leaf field values Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ffdae69 commit 2ca4684

25 files changed

Lines changed: 1511 additions & 291 deletions

File tree

baml_language/crates/baml_builtins2/baml_std/baml/ns_errors/errors.baml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,13 @@ class GenericSdkError {
8080
class CompilationError {
8181
message string
8282
}
83+
84+
/// A value/type mismatch at the call boundary — a caller passed an argument
85+
/// that doesn't fit the callee's (possibly inferred) type, a generic `TypeVar`
86+
/// could not be inferred and must be specified, or repeat occurrences of a
87+
/// `TypeVar` have no consistent binding. Synthesized host-side from
88+
/// `EngineError::TypeMismatch`; each host SDK surfaces it as its native
89+
/// type-error (Python `TypeError`).
90+
class TypeMismatch {
91+
message string
92+
}

baml_language/crates/baml_cli/src/snapshots/baml_cli__describe_command_tests__render_builtin_package_listing.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class baml.errors.DevOther <builtin>/baml/ns_errors/error
8686
class baml.errors.HostCallable <builtin>/baml/ns_errors/errors.baml:53
8787
class baml.errors.GenericSdkError <builtin>/baml/ns_errors/errors.baml:74
8888
class baml.errors.CompilationError <builtin>/baml/ns_errors/errors.baml:80
89+
class baml.errors.TypeMismatch <builtin>/baml/ns_errors/errors.baml:90
8990
class baml.errors.StackFrame <builtin>/baml/ns_errors/stack_trace.baml:2
9091
class baml.errors.StackTrace <builtin>/baml/ns_errors/stack_trace.baml:9
9192
class baml.fs.File <builtin>/baml/ns_fs/fs.baml:6

baml_language/crates/baml_compiler2_emit/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ pub fn generate_project_bytecode_with_opt(
869869
type_tag,
870870
ty_attr: TyAttr::default(),
871871
has_cleanup,
872+
generic_param_count: class_data.generic_params.len(),
872873
})));
873874
// Register with fully-qualified name for inter-package lookups.
874875
class_object_indices.insert(fq_name.clone(), class_obj_idx);

baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____03_hir.snap

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_tir.snap

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

baml_language/crates/baml_tests/src/compiler2_tir/snapshots/baml_tests__compiler2_tir__phase5__snapshot_baml_package_items.snap

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded.snap

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded_unoptimized.snap

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)