|
1 | 1 | use self::expression::CallKind;
|
2 | 2 |
|
3 |
| -use super::*; |
| 3 | +use super::{expression::ReferenceRegistration, *}; |
4 | 4 | use crate::ast::{
|
5 | 5 | FunctionLiteralKind, ImplicitCallArgOrigin, PIPE_VARIABLE, PipelineAssignmentKind, Statement,
|
6 | 6 | TypedPipelineAssignment, UntypedExpr,
|
@@ -139,17 +139,24 @@ impl<'a, 'b, 'c> PipeTyper<'a, 'b, 'c> {
|
139 | 139 | location,
|
140 | 140 | ..
|
141 | 141 | } => {
|
142 |
| - let fun = match self.expr_typer.infer_or_error(*fun) { |
| 142 | + let fun_result = match *fun { |
| 143 | + UntypedExpr::Var { location, name } => self.expr_typer.infer_var( |
| 144 | + name, |
| 145 | + location, |
| 146 | + VarUsage::PipelineCall, |
| 147 | + ReferenceRegistration::RegisterReferences, |
| 148 | + ), |
| 149 | + fun => self.expr_typer.infer_or_error(fun), |
| 150 | + }; |
| 151 | + |
| 152 | + let fun = match fun_result { |
143 | 153 | Ok(fun) => fun,
|
144 | 154 | Err(e) => {
|
145 | 155 | // In case we cannot infer the function we'll
|
146 | 156 | // replace it with an invalid expression with an
|
147 | 157 | // unbound type to keep going!
|
148 | 158 | self.expr_typer.problems.error(e);
|
149 |
| - TypedExpr::Invalid { |
150 |
| - location, |
151 |
| - type_: self.expr_typer.new_unbound_var(), |
152 |
| - } |
| 159 | + self.expr_typer.error_expr(location) |
153 | 160 | }
|
154 | 161 | };
|
155 | 162 |
|
@@ -350,16 +357,26 @@ impl<'a, 'b, 'c> PipeTyper<'a, 'b, 'c> {
|
350 | 357 | /// b is the `function` argument.
|
351 | 358 | fn infer_apply_pipe(&mut self, function: UntypedExpr) -> TypedExpr {
|
352 | 359 | let function_location = function.location();
|
353 |
| - let function = Box::new(match self.expr_typer.infer_or_error(function) { |
| 360 | + // Need one more step for better error suggestion. If the function is |
| 361 | + // a variable / identifier, then we can suggest variables / identifier |
| 362 | + // from imported modules with the same name and same arity. |
| 363 | + let function_result = match function { |
| 364 | + UntypedExpr::Var { location, name } => self.expr_typer.infer_var( |
| 365 | + name, |
| 366 | + location, |
| 367 | + VarUsage::Call { arity: 1 }, |
| 368 | + ReferenceRegistration::RegisterReferences, |
| 369 | + ), |
| 370 | + _ => self.expr_typer.infer_or_error(function), |
| 371 | + }; |
| 372 | + |
| 373 | + let function = Box::new(match function_result { |
354 | 374 | Ok(function) => function,
|
355 | 375 | Err(error) => {
|
356 | 376 | // If we cannot infer the function we put an invalid expression
|
357 | 377 | // in its place so we can still keep going with the other steps.
|
358 | 378 | self.expr_typer.problems.error(error);
|
359 |
| - TypedExpr::Invalid { |
360 |
| - location: function_location, |
361 |
| - type_: self.expr_typer.new_unbound_var(), |
362 |
| - } |
| 379 | + self.expr_typer.error_expr(function_location) |
363 | 380 | }
|
364 | 381 | });
|
365 | 382 |
|
|
0 commit comments