@@ -15,7 +15,12 @@ import {
15
15
hasStaticConstant ,
16
16
hasStaticFunction ,
17
17
} from "./resolveDescriptors" ;
18
- import { printTypeRef , TypeRef , typeRefEquals } from "./types" ;
18
+ import {
19
+ FunctionParameter ,
20
+ printTypeRef ,
21
+ TypeRef ,
22
+ typeRefEquals ,
23
+ } from "./types" ;
19
24
import { StatementContext } from "./resolveStatements" ;
20
25
import { MapFunctions } from "../abi/map" ;
21
26
import { GlobalFunctions } from "../abi/global" ;
@@ -526,6 +531,20 @@ function resolveFieldAccess(
526
531
}
527
532
}
528
533
534
+ function checkParameterType (
535
+ expression : A . AstExpression ,
536
+ parameter : FunctionParameter ,
537
+ ctx : CompilerContext ,
538
+ ) {
539
+ const t = getExpType ( ctx , expression ) ;
540
+ if ( ! isAssignable ( t , parameter . type ) ) {
541
+ throwCompilationError (
542
+ `Cannot pass an expression of type "${ printTypeRef ( t ) } " to the parameter ${ idTextErr ( parameter . name ) } of type "${ printTypeRef ( parameter . type ) } "` ,
543
+ expression . loc ,
544
+ ) ;
545
+ }
546
+ }
547
+
529
548
function resolveStaticCall (
530
549
exp : A . AstStaticCall ,
531
550
sctx : StatementContext ,
@@ -587,14 +606,7 @@ function resolveStaticCall(
587
606
) ;
588
607
}
589
608
for ( const [ i , a ] of f . params . entries ( ) ) {
590
- const e = exp . args [ i ] ! ;
591
- const t = getExpType ( ctx , e ) ;
592
- if ( ! isAssignable ( t , a . type ) ) {
593
- throwCompilationError (
594
- `Invalid type "${ printTypeRef ( t ) } " for argument ${ idTextErr ( a . name ) } ` ,
595
- e . loc ,
596
- ) ;
597
- }
609
+ checkParameterType ( exp . args [ i ] ! , a , ctx ) ;
598
610
}
599
611
600
612
// Resolve return type
@@ -654,14 +666,7 @@ function resolveCall(
654
666
) ;
655
667
}
656
668
for ( const [ i , a ] of f . params . entries ( ) ) {
657
- const e = exp . args [ i ] ! ;
658
- const t = getExpType ( ctx , e ) ;
659
- if ( ! isAssignable ( t , a . type ) ) {
660
- throwCompilationError (
661
- `Invalid type "${ printTypeRef ( t ) } " for argument ${ idTextErr ( a . name ) } ` ,
662
- e . loc ,
663
- ) ;
664
- }
669
+ checkParameterType ( exp . args [ i ] ! , a , ctx ) ;
665
670
}
666
671
667
672
return registerExpType ( ctx , exp , f . returns ) ;
@@ -779,14 +784,7 @@ function resolveInitOf(
779
784
) ;
780
785
}
781
786
for ( const [ i , a ] of type . init . params . entries ( ) ) {
782
- const e = ast . args [ i ] ! ;
783
- const t = getExpType ( ctx , e ) ;
784
- if ( ! isAssignable ( t , a . type ) ) {
785
- throwCompilationError (
786
- `Invalid type "${ printTypeRef ( t ) } " for argument ${ idTextErr ( a . name ) } ` ,
787
- e . loc ,
788
- ) ;
789
- }
787
+ checkParameterType ( ast . args [ i ] ! , a , ctx ) ;
790
788
}
791
789
792
790
// Register return type
0 commit comments