|
17 | 17 | /// |
18 | 18 | /// However, the current implementation is simple and ad-hoc, likely wrong |
19 | 19 | /// in several places. Bidirectional typing is the target. |
20 | | -use std::{borrow::Cow, sync::Arc}; |
| 20 | +use std::{borrow::Cow, str::FromStr, sync::Arc}; |
21 | 21 |
|
22 | 22 | use baml_types::{ |
23 | 23 | ir_type::{ArrowGeneric, TypeIR}, |
24 | 24 | BamlMap, BamlMediaType, BamlValueWithMeta, TypeValue, |
25 | 25 | }; |
| 26 | +use baml_vm::types::Type; |
26 | 27 | use internal_baml_ast::ast::WithSpan; |
27 | 28 | use internal_baml_diagnostics::{DatamodelError, Diagnostics, Span}; |
28 | 29 |
|
@@ -1356,6 +1357,7 @@ pub fn typecheck_expression( |
1356 | 1357 | "image" | "audio" | "video" | "pdf" | "baml" => {} |
1357 | 1358 |
|
1358 | 1359 | cls if context.classes.contains_key(cls) => {} |
| 1360 | + p if TypeValue::from_str(p).is_ok() => {} |
1359 | 1361 |
|
1360 | 1362 | _ => { |
1361 | 1363 | diagnostics.push_error(DatamodelError::new_validation_error( |
@@ -2344,17 +2346,22 @@ pub fn typecheck_expression( |
2344 | 2346 | thir::Expr::Var(name, _) => { |
2345 | 2347 | if context.classes.get(name).is_some() { |
2346 | 2348 | Some(TypeIR::bool()) |
| 2349 | + } else if context.enums.get(name).is_some() { |
| 2350 | + Some(TypeIR::bool()) |
| 2351 | + } else if TypeValue::from_str(name).is_ok() { |
| 2352 | + Some(TypeIR::bool()) |
2347 | 2353 | } else { |
| 2354 | + // TODO: Check type aliases (may be recursive) |
2348 | 2355 | diagnostics.push_error(DatamodelError::new_validation_error( |
2349 | | - &format!("Class {name} not found"), |
| 2356 | + &format!("Type {name} not found"), |
2350 | 2357 | span.clone(), |
2351 | 2358 | )); |
2352 | 2359 | None |
2353 | 2360 | } |
2354 | 2361 | } |
2355 | 2362 | _ => { |
2356 | 2363 | diagnostics.push_error(DatamodelError::new_validation_error( |
2357 | | - "Invalid binary operation (instanceof): right operand must be a class", |
| 2364 | + "Invalid binary operation (instanceof): right operand must be a type", |
2358 | 2365 | span.clone(), |
2359 | 2366 | )); |
2360 | 2367 | None |
|
0 commit comments