@@ -922,8 +922,8 @@ If no type annotation is provided, find the value type through
922
922
((not expected)
923
923
(push (list overload overload-index
924
924
(format
925
- " Argument %d is present but the function signature does not define it. Missing overload?"
926
- (1+ index)))
925
+ " Argument %s is present but the function signature does not define it. Missing overload?"
926
+ (if ( numberp index) ( 1+ index) index)))
927
927
overloads-errors))
928
928
((trinary-false-p acceptablep)
929
929
(push (list overload overload-index
@@ -934,16 +934,15 @@ If no type annotation is provided, find the value type through
934
934
; ; possible type is (const "whatever")
935
935
(elsa-with-temp-explainer explainer
936
936
(elsa-explain-and-indent explainer
937
- (" Argument %d accepts type `%s' but received `%s' "
938
- (1+ index)
937
+ (" Argument %s accepts type `%s' but received `%s' "
938
+ (if ( numberp index) ( 1+ index) index)
939
939
(elsa-type-describe expected-normalized)
940
940
(elsa-type-describe actual))
941
941
(elsa-type-accept expected-normalized actual explainer))
942
942
explainer))
943
943
overloads-errors)))
944
944
(and expected (trinary-possible-p acceptablep))))
945
945
overloads))
946
- ; ; (elsa-log "good-overloads %s" (mapconcat (lambda (x) (elsa-tostring (car x))) good-overloads " "))
947
946
(if good-overloads
948
947
; ; If we have multiple overloads where the argument is of a
949
948
; ; concrete type, that is not a sum or intersection (where the
@@ -955,9 +954,7 @@ If no type annotation is provided, find the value type through
955
954
; ; pick the last (smallest) one.
956
955
(if (= (length good-overloads) 1 )
957
956
(setq new-overloads good-overloads)
958
- (setq new-overloads (elsa--simplify-overloads good-overloads index))
959
- ; ; (elsa-log "new-overloads %s" (mapconcat (lambda (x) (elsa-tostring (car x))) new-overloads " "))
960
- )
957
+ (setq new-overloads (elsa--simplify-overloads good-overloads index)))
961
958
(setq new-overloads nil )
962
959
(elsa-state-add-message state
963
960
(if (< 1 (length overloads-errors))
@@ -975,7 +972,9 @@ If no type annotation is provided, find the value type through
975
972
(elsa-make-error argument-form
976
973
explainer
977
974
:code " no-overloads" ))
978
- (elsa-make-error argument-form
975
+ (elsa-make-error (if (keywordp index)
976
+ (oref argument-form previous)
977
+ argument-form)
979
978
(let ((expl-or-fmt (nth 2 (car overloads-errors))))
980
979
(if (elsa-explainer-p expl-or-fmt)
981
980
(elsa--reset-depth expl-or-fmt)
@@ -1011,35 +1010,37 @@ SCOPE and STATE are the scope and state objects."
1011
1010
(setq spec (elsa--analyse-normalize-spec spec form))
1012
1011
(let* ((name (elsa-get-name head))
1013
1012
(type (elsa-get-type head))
1014
- (narrow-type (elsa-function-get-narrow-type name)))
1013
+ (narrow-type (elsa-function-get-narrow-type name))
1014
+ (num-of-args (length args))
1015
+ (min 0 )
1016
+ (max num-of-args))
1015
1017
(-each (-zip args spec)
1016
1018
(-lambda ((arg . analysep))
1017
1019
(when analysep
1018
1020
(elsa--analyse-form arg scope state))))
1019
1021
; ; check arity
1020
1022
(when name
1021
- (-let (((min . max ) (elsa-fn-arity state name))
1022
- (num-of-args (length args)))
1023
- (when (eq max 'undefined )
1024
- (elsa-state-add-message state
1025
- (elsa-make-warning head
1026
- " Function `%s' is missing arglist definition. Maybe it is called before being declared?"
1027
- name)))
1028
- (when (< num-of-args min )
1029
- (elsa-state-add-message state
1030
- (elsa-make-error head
1031
- " Function `%s' expects at least %d %s but received %d"
1032
- name min
1033
- (elsa-pluralize " argument" min )
1034
- num-of-args)))
1035
- (when (and (not (memq max '(many unevalled undefined)))
1036
- (> num-of-args max ))
1037
- (elsa-state-add-message state
1038
- (elsa-make-error head
1039
- " Function `%s' expects at most %d %s but received %d"
1040
- name max
1041
- (elsa-pluralize " argument" max )
1042
- num-of-args)))))
1023
+ (-setq (min . max ) (elsa-fn-arity state name))
1024
+ (when (eq max 'undefined )
1025
+ (elsa-state-add-message state
1026
+ (elsa-make-warning head
1027
+ " Function `%s' is missing arglist definition. Maybe it is called before being declared?"
1028
+ name)))
1029
+ (when (< num-of-args min )
1030
+ (elsa-state-add-message state
1031
+ (elsa-make-error head
1032
+ " Function `%s' expects at least %d %s but received %d"
1033
+ name min
1034
+ (elsa-pluralize " argument" min )
1035
+ num-of-args)))
1036
+ (when (and (not (memq max '(many unevalled undefined)))
1037
+ (> num-of-args max ))
1038
+ (elsa-state-add-message state
1039
+ (elsa-make-error head
1040
+ " Function `%s' expects at most %d %s but received %d"
1041
+ name max
1042
+ (elsa-pluralize " argument" max )
1043
+ num-of-args))))
1043
1044
; ; check the types
1044
1045
(when type
1045
1046
; ; analyse the arguments
@@ -1054,13 +1055,38 @@ SCOPE and STATE are the scope and state objects."
1054
1055
(overloads (--map-indexed (cons it it-index) all-overloads)))
1055
1056
(-each-indexed args
1056
1057
(lambda (index argument-form )
1057
- (let ((check-results (elsa--check-argument-for-index
1058
- index argument-form overloads state
1059
- all-overloads overloads-errors)))
1060
- (setq overloads-errors
1061
- (append overloads-errors (plist-get check-results :errors )))
1062
- (setq overloads (plist-get check-results :overloads ))
1063
- (unless overloads (throw 'no-overloads nil )))))
1058
+ (when-let ((arg-idx (cond
1059
+ ((< index min ) index)
1060
+ ((symbolp max )
1061
+ ; ; this is most likely a
1062
+ ; ; keyword argument, so we
1063
+ ; ; check if it's a keyword
1064
+ ; ; and if so pass it forward
1065
+ (cond
1066
+ ; ; if this index is a
1067
+ ; ; keyword, we just skip to
1068
+ ; ; the next argument form.
1069
+ ((and (elsa-form-keyword-p argument-form)
1070
+ (cl-evenp (- index min )))
1071
+ nil )
1072
+ ; ; if the previous form was
1073
+ ; ; a keyword, that's the
1074
+ ; ; thing we need to look up
1075
+ ((elsa-form-keyword-p
1076
+ (oref argument-form previous))
1077
+ (elsa-form-to-lisp
1078
+ (oref argument-form previous)))
1079
+ (t index)))
1080
+ (t index))))
1081
+ (let ((check-results
1082
+ (elsa--check-argument-for-index
1083
+ arg-idx
1084
+ argument-form overloads state
1085
+ all-overloads overloads-errors)))
1086
+ (setq overloads-errors
1087
+ (append overloads-errors (plist-get check-results :errors )))
1088
+ (setq overloads (plist-get check-results :overloads ))
1089
+ (unless overloads (throw 'no-overloads nil ))))))
1064
1090
(mapcar #'car overloads))))))
1065
1091
; ; set the return type of the form according to the return type
1066
1092
; ; of the function's declaration
0 commit comments