@@ -191,8 +191,7 @@ fn get_warnings(
191
191
target,
192
192
TargetSupport :: NotEnforced ,
193
193
gleam_version,
194
- )
195
- . expect ( "Compilation should succeed" ) ;
194
+ ) ;
196
195
warnings. take ( ) . into_iter ( ) . collect_vec ( )
197
196
}
198
197
@@ -455,7 +454,7 @@ pub fn compile_module(
455
454
src : & str ,
456
455
warnings : Option < Rc < dyn WarningEmitterIO > > ,
457
456
dep : Vec < DependencyModule < ' _ > > ,
458
- ) -> Result < TypedModule , ( Vec < crate :: type_ :: Error > , Names ) > {
457
+ ) -> Outcome < TypedModule , Vec1 < super :: Error > > {
459
458
compile_module_with_opts (
460
459
module_name,
461
460
src,
@@ -475,7 +474,7 @@ pub fn compile_module_with_opts(
475
474
target : Target ,
476
475
target_support : TargetSupport ,
477
476
gleam_version : Option < Range < Version > > ,
478
- ) -> Result < TypedModule , ( Vec < crate :: type_ :: Error > , Names ) > {
477
+ ) -> Outcome < TypedModule , Vec1 < super :: Error > > {
479
478
let ids = UniqueIdGenerator :: new ( ) ;
480
479
let mut modules = im:: HashMap :: new ( ) ;
481
480
@@ -527,7 +526,7 @@ pub fn compile_module_with_opts(
527
526
config. gleam_version = gleam_version. map ( |v| GleamVersion :: from_pubgrub ( v) ) ;
528
527
529
528
let warnings = TypeWarningEmitter :: new ( "/src/warning/wrn.gleam" . into ( ) , src. into ( ) , emitter) ;
530
- let inference_result = crate :: analyse:: ModuleAnalyzerConstructor :: < ( ) > {
529
+ crate :: analyse:: ModuleAnalyzerConstructor :: < ( ) > {
531
530
target,
532
531
ids : & ids,
533
532
origin : Origin :: Src ,
@@ -538,13 +537,7 @@ pub fn compile_module_with_opts(
538
537
target_support : TargetSupport :: Enforced ,
539
538
package_config : & config,
540
539
}
541
- . infer_module ( ast, LineNumbers :: new ( src) , "" . into ( ) ) ;
542
-
543
- match inference_result {
544
- Outcome :: Ok ( ast) => Ok ( ast) ,
545
- Outcome :: PartialFailure ( ast, errors) => Err ( ( errors. into ( ) , ast. names ) ) ,
546
- Outcome :: TotalFailure ( error) => Err ( ( error. into ( ) , Default :: default ( ) ) ) ,
547
- }
540
+ . infer_module ( ast, LineNumbers :: new ( src) , "" . into ( ) )
548
541
}
549
542
550
543
pub fn module_error ( src : & str , deps : Vec < DependencyModule < ' _ > > ) -> String {
@@ -556,16 +549,22 @@ pub fn module_error_with_target(
556
549
deps : Vec < DependencyModule < ' _ > > ,
557
550
target : Target ,
558
551
) -> String {
559
- let ( error , names ) = compile_module_with_opts (
552
+ let outcome = compile_module_with_opts (
560
553
"themodule" ,
561
554
src,
562
555
None ,
563
556
deps,
564
557
target,
565
558
TargetSupport :: NotEnforced ,
566
559
None ,
567
- )
568
- . expect_err ( "should infer an error" ) ;
560
+ ) ;
561
+
562
+ let ( error, names) = match outcome {
563
+ Outcome :: Ok ( _) => panic ! ( "should infer an error" ) ,
564
+ Outcome :: PartialFailure ( ast, errors) => ( errors. into ( ) , ast. names ) ,
565
+ Outcome :: TotalFailure ( errors) => ( errors. into ( ) , Default :: default ( ) ) ,
566
+ } ;
567
+
569
568
let error = Error :: Type {
570
569
names : Box :: new ( names) ,
571
570
src : src. into ( ) ,
@@ -584,16 +583,22 @@ pub fn internal_module_error_with_target(
584
583
deps : Vec < DependencyModule < ' _ > > ,
585
584
target : Target ,
586
585
) -> String {
587
- let ( error , names ) = compile_module_with_opts (
586
+ let outcome = compile_module_with_opts (
588
587
"thepackage/internal/themodule" ,
589
588
src,
590
589
None ,
591
590
deps,
592
591
target,
593
592
TargetSupport :: NotEnforced ,
594
593
None ,
595
- )
596
- . expect_err ( "should infer an error" ) ;
594
+ ) ;
595
+
596
+ let ( error, names) = match outcome {
597
+ Outcome :: Ok ( _) => panic ! ( "should infer an error" ) ,
598
+ Outcome :: PartialFailure ( ast, errors) => ( errors. into ( ) , ast. names ) ,
599
+ Outcome :: TotalFailure ( errors) => ( errors. into ( ) , Default :: default ( ) ) ,
600
+ } ;
601
+
597
602
let error = Error :: Type {
598
603
names : Box :: new ( names) ,
599
604
src : src. into ( ) ,
0 commit comments