|
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 |
|
@@ -1371,6 +1372,7 @@ pub fn typecheck_expression( |
1371 | 1372 | "image" | "audio" | "video" | "pdf" | "baml" => {} |
1372 | 1373 |
|
1373 | 1374 | cls if context.classes.contains_key(cls) => {} |
| 1375 | + p if TypeValue::from_str(p).is_ok() => {} |
1374 | 1376 |
|
1375 | 1377 | _ => { |
1376 | 1378 | diagnostics.push_error(DatamodelError::new_validation_error( |
@@ -2487,17 +2489,22 @@ pub fn typecheck_expression( |
2487 | 2489 | thir::Expr::Var(name, _) => { |
2488 | 2490 | if context.classes.get(name).is_some() { |
2489 | 2491 | Some(TypeIR::bool()) |
| 2492 | + } else if context.enums.get(name).is_some() { |
| 2493 | + Some(TypeIR::bool()) |
| 2494 | + } else if TypeValue::from_str(name).is_ok() { |
| 2495 | + Some(TypeIR::bool()) |
2490 | 2496 | } else { |
| 2497 | + // TODO: Check type aliases (may be recursive) |
2491 | 2498 | diagnostics.push_error(DatamodelError::new_validation_error( |
2492 | | - &format!("Class {name} not found"), |
| 2499 | + &format!("Type {name} not found"), |
2493 | 2500 | span.clone(), |
2494 | 2501 | )); |
2495 | 2502 | None |
2496 | 2503 | } |
2497 | 2504 | } |
2498 | 2505 | _ => { |
2499 | 2506 | diagnostics.push_error(DatamodelError::new_validation_error( |
2500 | | - "Invalid binary operation (instanceof): right operand must be a class", |
| 2507 | + "Invalid binary operation (instanceof): right operand must be a type", |
2501 | 2508 | span.clone(), |
2502 | 2509 | )); |
2503 | 2510 | None |
|
0 commit comments