@@ -271,6 +271,75 @@ pub(crate) enum Error<'a> {
271
271
expected : Range < u32 > ,
272
272
found : u32 ,
273
273
} ,
274
+ /// No overload of this function accepts this many arguments.
275
+ TooManyArguments {
276
+ /// The name of the function being called.
277
+ function : String ,
278
+
279
+ /// The function name in the call expression.
280
+ call_span : Span ,
281
+
282
+ /// The first argument that is unacceptable.
283
+ arg_span : Span ,
284
+
285
+ /// Maximum number of arguments accepted by any overload of
286
+ /// this function.
287
+ max_arguments : u32 ,
288
+ } ,
289
+ /// A value passed to a builtin function has a type that is not
290
+ /// accepted by any overload of the function.
291
+ WrongArgumentType {
292
+ /// The name of the function being called.
293
+ function : String ,
294
+
295
+ /// The function name in the call expression.
296
+ call_span : Span ,
297
+
298
+ /// The first argument whose type is unacceptable.
299
+ arg_span : Span ,
300
+
301
+ /// The index of the first argument whose type is unacceptable.
302
+ arg_index : u32 ,
303
+
304
+ /// That argument's actual type.
305
+ arg_ty : String ,
306
+
307
+ /// The set of argument types that would have been accepted for
308
+ /// this argument, given the prior arguments.
309
+ allowed : Vec < String > ,
310
+ } ,
311
+ /// A value passed to a builtin function has a type that is not
312
+ /// accepted, given the earlier arguments' types.
313
+ InconsistentArgumentType {
314
+ /// The name of the function being called.
315
+ function : String ,
316
+
317
+ /// The function name in the call expression.
318
+ call_span : Span ,
319
+
320
+ /// The first unacceptable argument.
321
+ arg_span : Span ,
322
+
323
+ /// The index of the first unacceptable argument.
324
+ arg_index : u32 ,
325
+
326
+ /// The actual type of the first unacceptable argument.
327
+ arg_ty : String ,
328
+
329
+ /// The prior argument whose type made the `arg_span` argument
330
+ /// unacceptable.
331
+ inconsistent_span : Span ,
332
+
333
+ /// The index of the `inconsistent_span` argument.
334
+ inconsistent_index : u32 ,
335
+
336
+ /// The type of the `inconsistent_span` argument.
337
+ inconsistent_ty : String ,
338
+
339
+ /// The types that would have been accepted instead of the
340
+ /// first unacceptable argument.
341
+ allowed : Vec < String > ,
342
+ } ,
274
343
FunctionReturnsVoid ( Span ) ,
275
344
FunctionMustUseUnused ( Span ) ,
276
345
FunctionMustUseReturnsVoid ( Span , Span ) ,
@@ -402,7 +471,8 @@ impl<'a> Error<'a> {
402
471
"workgroup size separator (`,`) or a closing parenthesis" . to_string ( )
403
472
}
404
473
ExpectedToken :: GlobalItem => concat ! (
405
- "global item (`struct`, `const`, `var`, `alias`, `fn`, `diagnostic`, `enable`, `requires`, `;`) " ,
474
+ "global item (`struct`, `const`, `var`, `alias`, " ,
475
+ "`fn`, `diagnostic`, `enable`, `requires`, `;`) " ,
406
476
"or the end of the file"
407
477
)
408
478
. to_string ( ) ,
@@ -831,6 +901,74 @@ impl<'a> Error<'a> {
831
901
labels : vec ! [ ( span, "wrong number of arguments" . into( ) ) ] ,
832
902
notes : vec ! [ ] ,
833
903
} ,
904
+ Error :: TooManyArguments {
905
+ ref function,
906
+ call_span,
907
+ arg_span,
908
+ max_arguments,
909
+ } => ParseError {
910
+ message : format ! ( "too many arguments passed to `{function}`" ) ,
911
+ labels : vec ! [
912
+ ( call_span, "" . into( ) ) ,
913
+ ( arg_span, format!( "unexpected argument #{}" , max_arguments + 1 ) . into( ) )
914
+ ] ,
915
+ notes : vec ! [
916
+ format!( "The `{function}` function accepts at most {max_arguments} argument(s)" )
917
+ ] ,
918
+ } ,
919
+ Error :: WrongArgumentType {
920
+ ref function,
921
+ call_span,
922
+ arg_span,
923
+ arg_index,
924
+ ref arg_ty,
925
+ ref allowed,
926
+ } => {
927
+ let message = format ! (
928
+ "wrong type passed as argument #{} to `{function}`" ,
929
+ arg_index + 1 ,
930
+ ) ;
931
+ let labels = vec ! [
932
+ ( call_span, "" . into( ) ) ,
933
+ ( arg_span, format!( "argument #{} has type `{arg_ty}`" , arg_index + 1 ) . into( ) )
934
+ ] ;
935
+
936
+ let mut notes = vec ! [ ] ;
937
+ notes. push ( format ! ( "`{function}` accepts the following types for argument #{}:" , arg_index + 1 ) ) ;
938
+ notes. extend ( allowed. iter ( ) . map ( |ty| format ! ( "allowed type: {ty}" ) ) ) ;
939
+
940
+ ParseError { message, labels, notes }
941
+ } ,
942
+ Error :: InconsistentArgumentType {
943
+ ref function,
944
+ call_span,
945
+ arg_span,
946
+ arg_index,
947
+ ref arg_ty,
948
+ inconsistent_span,
949
+ inconsistent_index,
950
+ ref inconsistent_ty,
951
+ ref allowed
952
+ } => {
953
+ let message = format ! (
954
+ "inconsistent type passed as argument #{} to `{function}`" ,
955
+ arg_index + 1 ,
956
+ ) ;
957
+ let labels = vec ! [
958
+ ( call_span, "" . into( ) ) ,
959
+ ( arg_span, format!( "argument #{} has type {arg_ty}" , arg_index + 1 ) . into( ) ) ,
960
+ ( inconsistent_span, format!(
961
+ "this argument has type {inconsistent_ty}, which constrains subsequent arguments"
962
+ ) . into( ) ) ,
963
+ ] ;
964
+ let mut notes = vec ! [
965
+ format!( "Because argument #{} has type {inconsistent_ty}, only the following types" , inconsistent_index + 1 ) ,
966
+ format!( "(or types that automatically convert to them) are accepted for argument #{}:" , arg_index + 1 ) ,
967
+ ] ;
968
+ notes. extend ( allowed. iter ( ) . map ( |ty| format ! ( "allowed type: {ty}" ) ) ) ;
969
+
970
+ ParseError { message, labels, notes }
971
+ }
834
972
Error :: FunctionReturnsVoid ( span) => ParseError {
835
973
message : "function does not return any value" . to_string ( ) ,
836
974
labels : vec ! [ ( span, "" . into( ) ) ] ,
0 commit comments