|
1 | 1 | use std::collections::HashMap; |
2 | 2 | use strum::IntoEnumIterator; |
3 | 3 |
|
4 | | -use crate::common::{bug, bug_span, context, err, err_span, maybe_format_span, AnyError}; |
| 4 | +use crate::common::{bug_span, context, err, err_span, maybe_format_span, AnyError}; |
5 | 5 | use crate::frontend::expression::display::typed_identifiers_to_str; |
6 | 6 | use crate::frontend::expression::{ |
7 | 7 | is_macro, Branch, Browse, BrowseOr, Chain, Composed, Comptime, Expression, ExpressionSpan, |
@@ -127,7 +127,7 @@ impl<'a> Typer<'a> { |
127 | 127 | .get_main() |
128 | 128 | .file |
129 | 129 | .as_ref() |
130 | | - .map(|p| format!("{}", p.to_string_lossy())); |
| 130 | + .map(|p| p.to_string_lossy().to_string()); |
131 | 131 | Ok((typer, program.main())) |
132 | 132 | } |
133 | 133 |
|
@@ -228,21 +228,26 @@ impl<'a> Typer<'a> { |
228 | 228 | } |
229 | 229 | } |
230 | 230 |
|
231 | | - fn get_identifier_type(&self, name: &String) -> Result<Type, AnyError> { |
| 231 | + fn get_identifier_type(&self, name: &String, span: Span) -> Result<Type, AnyError> { |
232 | 232 | if let Some(types) = self.identifier_types.get(name) { |
233 | 233 | if let Some(last) = types.last() { |
234 | 234 | Ok(last.clone()) |
235 | 235 | } else { |
236 | | - err(format!( |
237 | | - "Bug: Identifier '{}' is not bound to any value", |
238 | | - name |
239 | | - )) |
| 236 | + bug_span( |
| 237 | + format!("Identifier '{}' is not bound to any value", name), |
| 238 | + self.get_current_source(), |
| 239 | + span, |
| 240 | + ) |
240 | 241 | } |
241 | 242 | } else { |
242 | | - err(format!( |
243 | | - "Bug: Undefined identifier '{}'. This should have been detected by earlier stages.", |
244 | | - name |
245 | | - )) |
| 243 | + bug_span( |
| 244 | + format!( |
| 245 | + "Undefined identifier '{}'. This should have been detected by earlier stages.", |
| 246 | + name |
| 247 | + ), |
| 248 | + self.get_current_source(), |
| 249 | + span, |
| 250 | + ) |
246 | 251 | } |
247 | 252 | } |
248 | 253 | } |
@@ -294,7 +299,7 @@ impl<'a> Typer<'a> { |
294 | 299 | ) -> Result<ExpressionSpan, AnyError> { |
295 | 300 | Ok(ExpressionSpan::new( |
296 | 301 | Expression::Identifier(name.clone()), |
297 | | - self.get_identifier_type(name)?, |
| 302 | + self.get_identifier_type(name, span)?, |
298 | 303 | span, |
299 | 304 | )) |
300 | 305 | } |
@@ -556,6 +561,11 @@ impl<'a> Typer<'a> { |
556 | 561 | Ok(Operation::single(operator, typed_operand, type_)) |
557 | 562 | } |
558 | 563 | Operator::Call => self.get_call_type(input, operands, operator.span), |
| 564 | + // Operator::MacroCall => Ok(Operation::several( |
| 565 | + // operator, |
| 566 | + // operands.clone(), |
| 567 | + // builtin_types::ANY, |
| 568 | + // )), |
559 | 569 | Operator::MacroCall => bug_span( |
560 | 570 | "macro calls should not reach the typing stage. Macro call", |
561 | 571 | self.sources.get_main(), |
@@ -633,7 +643,7 @@ impl<'a> Typer<'a> { |
633 | 643 | let mut callable = operands.get(0).unwrap().clone(); |
634 | 644 | match &callable.syntactic_type { |
635 | 645 | Expression::Identifier(name) => { |
636 | | - callable.semantic_type = self.get_identifier_type(name)?; |
| 646 | + callable.semantic_type = self.get_identifier_type(name, callable.span)?; |
637 | 647 | self.check_type_callable(input_type, callable, &operands[1..], operator_span) |
638 | 648 | } |
639 | 649 | Expression::Chain(chain) => { |
|
0 commit comments