@@ -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 {
@@ -3470,7 +3470,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3470
3470
module : & Option < ( EcoString , SrcSpan ) > ,
3471
3471
name : & EcoString ,
3472
3472
location : & SrcSpan ,
3473
- var_usage : VarUsage ,
3473
+ var_usage : ValueUsage ,
3474
3474
) -> Result < ValueConstructor , Error > {
3475
3475
self . do_infer_value_constructor (
3476
3476
module,
@@ -3486,7 +3486,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3486
3486
module : & Option < ( EcoString , SrcSpan ) > ,
3487
3487
name : & EcoString ,
3488
3488
location : & SrcSpan ,
3489
- var_usage : VarUsage ,
3489
+ var_usage : ValueUsage ,
3490
3490
register_reference : ReferenceRegistration ,
3491
3491
) -> Result < ValueConstructor , Error > {
3492
3492
let constructor = match module {
@@ -3627,7 +3627,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3627
3627
& mut self ,
3628
3628
name : & EcoString ,
3629
3629
location : & SrcSpan ,
3630
- var_usage : VarUsage ,
3630
+ var_usage : ValueUsage ,
3631
3631
) -> Error {
3632
3632
// First try to see if this is a module alias:
3633
3633
// `import gleam/io`
@@ -3640,47 +3640,21 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3640
3640
name : name. clone ( ) ,
3641
3641
} ,
3642
3642
None => {
3643
- let imported_modules_with_same_public_variable_name = match var_usage {
3643
+ let possible_modules = match var_usage {
3644
3644
// This is a function call, we need to suggest a public
3645
- // variable which is a function with the correct arity
3646
- VarUsage :: Call { arity } => self
3645
+ // value which is a function with the correct arity
3646
+ ValueUsage :: Call { arity } => self
3647
3647
. environment
3648
3648
. imported_modules
3649
3649
. iter ( )
3650
3650
. filter_map ( |( module_name, ( _, module) ) | {
3651
- module
3652
- . get_public_value ( name)
3653
- . filter ( |value_constructor| {
3654
- match value_constructor. type_ . fn_types ( ) {
3655
- Some ( ( fn_arguments_type, _) ) => {
3656
- fn_arguments_type. len ( ) == arity
3657
- }
3658
- None => false ,
3659
- }
3660
- } )
3661
- . map ( |_| module_name)
3662
- } )
3663
- . cloned ( )
3664
- . collect_vec ( ) ,
3665
- // This is a `Call` into a `Pipeline`. This is hard to make
3666
- // good suggestions because of the way it can be desugared.
3667
- // In this case, return every functions with the same name
3668
- // even if they have wrong arity.
3669
- VarUsage :: PipelineCall => self
3670
- . environment
3671
- . imported_modules
3672
- . iter ( )
3673
- . filter_map ( |( module_name, ( _, module) ) | {
3674
- module
3675
- . get_public_value ( name)
3676
- . filter ( |value_constructor| value_constructor. type_ . is_fun ( ) )
3677
- . map ( |_| module_name)
3651
+ module. get_public_function ( name, arity) . map ( |_| module_name)
3678
3652
} )
3679
3653
. cloned ( )
3680
3654
. collect_vec ( ) ,
3681
3655
// This is a reference to a variable, we need to suggest
3682
- // public variables of any type
3683
- VarUsage :: Other => self
3656
+ // a public value of any type
3657
+ ValueUsage :: Other => self
3684
3658
. environment
3685
3659
. imported_modules
3686
3660
. iter ( )
@@ -3705,7 +3679,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3705
3679
. module_types
3706
3680
. keys ( )
3707
3681
. any ( |typ| typ == name) ,
3708
- imported_modules_with_same_public_variable_name ,
3682
+ possible_modules ,
3709
3683
}
3710
3684
}
3711
3685
}
@@ -3766,7 +3740,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3766
3740
} if arguments. is_empty ( ) => {
3767
3741
// Type check the record constructor
3768
3742
let constructor =
3769
- self . infer_value_constructor ( & module, & name, & location, VarUsage :: Other ) ?;
3743
+ self . infer_value_constructor ( & module, & name, & location, ValueUsage :: Other ) ?;
3770
3744
3771
3745
let ( tag, field_map) = match & constructor. variant {
3772
3746
ValueConstructorVariant :: Record {
@@ -3809,7 +3783,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3809
3783
& module,
3810
3784
& name,
3811
3785
& location,
3812
- VarUsage :: Call {
3786
+ ValueUsage :: Call {
3813
3787
arity : arguments. len ( ) ,
3814
3788
} ,
3815
3789
) ?;
@@ -3955,7 +3929,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
3955
3929
} => {
3956
3930
// Infer the type of this constant
3957
3931
let constructor =
3958
- self . infer_value_constructor ( & module, & name, & location, VarUsage :: Other ) ?;
3932
+ self . infer_value_constructor ( & module, & name, & location, ValueUsage :: Other ) ?;
3959
3933
match constructor. variant {
3960
3934
ValueConstructorVariant :: ModuleConstant { .. }
3961
3935
| ValueConstructorVariant :: LocalConstant { .. }
@@ -4133,27 +4107,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
4133
4107
) -> ( TypedExpr , Vec < TypedCallArg > , Arc < Type > ) {
4134
4108
let fun = match fun {
4135
4109
UntypedExpr :: Var { location, name } => {
4136
- // Because we are not calling infer / infer_or_error directly,
4137
- // we do not warn if there was a previous panic. Check for that
4138
- // here. Not perfect, but works.
4139
- if self . previous_panics {
4140
- self . warn_for_unreachable_code ( location, PanicPosition :: PreviousExpression ) ;
4141
- }
4142
-
4143
- match self . infer_var (
4144
- name,
4145
- location,
4146
- VarUsage :: Call {
4147
- arity : arguments. len ( ) ,
4148
- } ,
4149
- ReferenceRegistration :: RegisterReferences ,
4150
- ) {
4151
- Ok ( typed_expr) => typed_expr,
4152
- Err ( error) => {
4153
- self . problems . error ( error) ;
4154
- self . error_expr ( location)
4155
- }
4156
- }
4110
+ self . infer_called_var ( name, location, arguments. len ( ) )
4157
4111
}
4158
4112
4159
4113
UntypedExpr :: FieldAccess {
@@ -4193,6 +4147,26 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
4193
4147
( fun, arguments, type_)
4194
4148
}
4195
4149
4150
+ pub fn infer_called_var (
4151
+ & mut self ,
4152
+ name : EcoString ,
4153
+ location : SrcSpan ,
4154
+ arity : usize ,
4155
+ ) -> TypedExpr {
4156
+ match self . infer_var (
4157
+ name,
4158
+ location,
4159
+ ValueUsage :: Call { arity } ,
4160
+ ReferenceRegistration :: RegisterReferences ,
4161
+ ) {
4162
+ Ok ( typed_expr) => typed_expr,
4163
+ Err ( error) => {
4164
+ self . problems . error ( error) ;
4165
+ self . error_expr ( location)
4166
+ }
4167
+ }
4168
+ }
4169
+
4196
4170
fn infer_fn_with_call_context (
4197
4171
& mut self ,
4198
4172
arguments : Vec < UntypedArg > ,
@@ -4755,7 +4729,7 @@ fn is_trusted_pure_module(environment: &Environment<'_>) -> bool {
4755
4729
}
4756
4730
4757
4731
#[ derive( Debug , Clone , Copy ) ]
4758
- pub ( crate ) enum ReferenceRegistration {
4732
+ enum ReferenceRegistration {
4759
4733
RegisterReferences ,
4760
4734
DoNotRegisterReferences ,
4761
4735
}
0 commit comments