@@ -435,7 +435,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
435
435
UntypedExpr :: Var { location, name, .. } => self . infer_var (
436
436
name,
437
437
location,
438
- VarUsage :: Other ,
438
+ ValueUsage :: Other ,
439
439
ReferenceRegistration :: RegisterReferences ,
440
440
) ,
441
441
@@ -727,7 +727,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
727
727
}
728
728
729
729
// Helper to create a new error expr.
730
- pub ( crate ) fn error_expr ( & mut self , location : SrcSpan ) -> TypedExpr {
730
+ fn error_expr ( & mut self , location : SrcSpan ) -> TypedExpr {
731
731
TypedExpr :: Invalid {
732
732
location,
733
733
type_ : self . new_unbound_var ( ) ,
@@ -1246,11 +1246,11 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
1246
1246
}
1247
1247
}
1248
1248
1249
- pub ( crate ) fn infer_var (
1249
+ fn infer_var (
1250
1250
& mut self ,
1251
1251
name : EcoString ,
1252
1252
location : SrcSpan ,
1253
- var_usage : VarUsage ,
1253
+ var_usage : ValueUsage ,
1254
1254
register_reference : ReferenceRegistration ,
1255
1255
) -> Result < TypedExpr , Error > {
1256
1256
let constructor = self . do_infer_value_constructor (
@@ -1354,7 +1354,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
1354
1354
UntypedExpr :: Var { location, name } => self . infer_var (
1355
1355
name,
1356
1356
location,
1357
- VarUsage :: Other ,
1357
+ ValueUsage :: Other ,
1358
1358
ReferenceRegistration :: DoNotRegisterReferences ,
1359
1359
) ,
1360
1360
_ => self . infer_or_error ( container) ,
@@ -2320,7 +2320,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
2320
2320
match guard {
2321
2321
ClauseGuard :: Var { location, name, .. } => {
2322
2322
let constructor =
2323
- self . infer_value_constructor ( & None , & name, & location, VarUsage :: Other ) ?;
2323
+ self . infer_value_constructor ( & None , & name, & location, ValueUsage :: Other ) ?;
2324
2324
2325
2325
// We cannot support all values in guard expressions as the BEAM does not
2326
2326
let definition_location = match & constructor. variant {
@@ -3483,7 +3483,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3483
3483
module : & Option < ( EcoString , SrcSpan ) > ,
3484
3484
name : & EcoString ,
3485
3485
location : & SrcSpan ,
3486
- var_usage : VarUsage ,
3486
+ var_usage : ValueUsage ,
3487
3487
) -> Result < ValueConstructor , Error > {
3488
3488
self . do_infer_value_constructor (
3489
3489
module,
@@ -3499,7 +3499,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3499
3499
module : & Option < ( EcoString , SrcSpan ) > ,
3500
3500
name : & EcoString ,
3501
3501
location : & SrcSpan ,
3502
- var_usage : VarUsage ,
3502
+ var_usage : ValueUsage ,
3503
3503
register_reference : ReferenceRegistration ,
3504
3504
) -> Result < ValueConstructor , Error > {
3505
3505
let constructor = match module {
@@ -3640,7 +3640,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3640
3640
& mut self ,
3641
3641
name : & EcoString ,
3642
3642
location : & SrcSpan ,
3643
- var_usage : VarUsage ,
3643
+ var_usage : ValueUsage ,
3644
3644
) -> Error {
3645
3645
// First try to see if this is a module alias:
3646
3646
// `import gleam/io`
@@ -3653,47 +3653,21 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3653
3653
name : name. clone ( ) ,
3654
3654
} ,
3655
3655
None => {
3656
- let imported_modules_with_same_public_variable_name = match var_usage {
3656
+ let possible_modules = match var_usage {
3657
3657
// This is a function call, we need to suggest a public
3658
- // variable which is a function with the correct arity
3659
- VarUsage :: Call { arity } => self
3658
+ // value which is a function with the correct arity
3659
+ ValueUsage :: Call { arity } => self
3660
3660
. environment
3661
3661
. imported_modules
3662
3662
. iter ( )
3663
3663
. filter_map ( |( module_name, ( _, module) ) | {
3664
- module
3665
- . get_public_value ( name)
3666
- . filter ( |value_constructor| {
3667
- match value_constructor. type_ . fn_types ( ) {
3668
- Some ( ( fn_arguments_type, _) ) => {
3669
- fn_arguments_type. len ( ) == arity
3670
- }
3671
- None => false ,
3672
- }
3673
- } )
3674
- . map ( |_| module_name)
3675
- } )
3676
- . cloned ( )
3677
- . collect_vec ( ) ,
3678
- // This is a `Call` into a `Pipeline`. This is hard to make
3679
- // good suggestions because of the way it can be desugared.
3680
- // In this case, return every functions with the same name
3681
- // even if they have wrong arity.
3682
- VarUsage :: PipelineCall => self
3683
- . environment
3684
- . imported_modules
3685
- . iter ( )
3686
- . filter_map ( |( module_name, ( _, module) ) | {
3687
- module
3688
- . get_public_value ( name)
3689
- . filter ( |value_constructor| value_constructor. type_ . is_fun ( ) )
3690
- . map ( |_| module_name)
3664
+ module. get_public_function ( name, arity) . map ( |_| module_name)
3691
3665
} )
3692
3666
. cloned ( )
3693
3667
. collect_vec ( ) ,
3694
3668
// This is a reference to a variable, we need to suggest
3695
- // public variables of any type
3696
- VarUsage :: Other => self
3669
+ // a public value of any type
3670
+ ValueUsage :: Other => self
3697
3671
. environment
3698
3672
. imported_modules
3699
3673
. iter ( )
@@ -3718,7 +3692,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3718
3692
. module_types
3719
3693
. keys ( )
3720
3694
. any ( |typ| typ == name) ,
3721
- imported_modules_with_same_public_variable_name ,
3695
+ possible_modules ,
3722
3696
}
3723
3697
}
3724
3698
}
@@ -3779,7 +3753,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3779
3753
} if arguments. is_empty ( ) => {
3780
3754
// Type check the record constructor
3781
3755
let constructor =
3782
- self . infer_value_constructor ( & module, & name, & location, VarUsage :: Other ) ?;
3756
+ self . infer_value_constructor ( & module, & name, & location, ValueUsage :: Other ) ?;
3783
3757
3784
3758
let ( tag, field_map) = match & constructor. variant {
3785
3759
ValueConstructorVariant :: Record {
@@ -3822,7 +3796,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3822
3796
& module,
3823
3797
& name,
3824
3798
& location,
3825
- VarUsage :: Call {
3799
+ ValueUsage :: Call {
3826
3800
arity : arguments. len ( ) ,
3827
3801
} ,
3828
3802
) ?;
@@ -3968,7 +3942,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3968
3942
} => {
3969
3943
// Infer the type of this constant
3970
3944
let constructor =
3971
- self . infer_value_constructor ( & module, & name, & location, VarUsage :: Other ) ?;
3945
+ self . infer_value_constructor ( & module, & name, & location, ValueUsage :: Other ) ?;
3972
3946
match constructor. variant {
3973
3947
ValueConstructorVariant :: ModuleConstant { .. }
3974
3948
| ValueConstructorVariant :: LocalConstant { .. }
@@ -4146,27 +4120,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
4146
4120
) -> ( TypedExpr , Vec < TypedCallArg > , Arc < Type > ) {
4147
4121
let fun = match fun {
4148
4122
UntypedExpr :: Var { location, name } => {
4149
- // Because we are not calling infer / infer_or_error directly,
4150
- // we do not warn if there was a previous panic. Check for that
4151
- // here. Not perfect, but works.
4152
- if self . previous_panics {
4153
- self . warn_for_unreachable_code ( location, PanicPosition :: PreviousExpression ) ;
4154
- }
4155
-
4156
- match self . infer_var (
4157
- name,
4158
- location,
4159
- VarUsage :: Call {
4160
- arity : arguments. len ( ) ,
4161
- } ,
4162
- ReferenceRegistration :: RegisterReferences ,
4163
- ) {
4164
- Ok ( typed_expr) => typed_expr,
4165
- Err ( error) => {
4166
- self . problems . error ( error) ;
4167
- self . error_expr ( location)
4168
- }
4169
- }
4123
+ self . infer_called_var ( name, location, arguments. len ( ) )
4170
4124
}
4171
4125
4172
4126
UntypedExpr :: FieldAccess {
@@ -4206,6 +4160,26 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
4206
4160
( fun, arguments, type_)
4207
4161
}
4208
4162
4163
+ pub fn infer_called_var (
4164
+ & mut self ,
4165
+ name : EcoString ,
4166
+ location : SrcSpan ,
4167
+ arity : usize ,
4168
+ ) -> TypedExpr {
4169
+ match self . infer_var (
4170
+ name,
4171
+ location,
4172
+ ValueUsage :: Call { arity } ,
4173
+ ReferenceRegistration :: RegisterReferences ,
4174
+ ) {
4175
+ Ok ( typed_expr) => typed_expr,
4176
+ Err ( error) => {
4177
+ self . problems . error ( error) ;
4178
+ self . error_expr ( location)
4179
+ }
4180
+ }
4181
+ }
4182
+
4209
4183
fn infer_fn_with_call_context (
4210
4184
& mut self ,
4211
4185
arguments : Vec < UntypedArg > ,
@@ -4768,7 +4742,7 @@ fn is_trusted_pure_module(environment: &Environment<'_>) -> bool {
4768
4742
}
4769
4743
4770
4744
#[ derive( Debug , Clone , Copy ) ]
4771
- pub ( crate ) enum ReferenceRegistration {
4745
+ enum ReferenceRegistration {
4772
4746
RegisterReferences ,
4773
4747
DoNotRegisterReferences ,
4774
4748
}
0 commit comments