diff --git a/collects/profj/check.ss b/collects/profj/check.ss index 0100636b25..c54098e510 100644 --- a/collects/profj/check.ss +++ b/collects/profj/check.ss @@ -2007,6 +2007,8 @@ (cond ;List of methods found ((list? call-exp) call-exp) + ((eq? call-exp 'null) + (prim-call-error call-exp name src level)) ((array-type? call-exp) (set! exp-type call-exp) (get-method-records name-string @@ -2769,11 +2771,13 @@ (t (type->ext-name exp))) (raise-error n - (format "attempted to call method ~a on ~a which does not have methods. ~nOnly values with ~a types have methods" - n t - (case level - ((beginner intermediate) "class or interface") - (else "class, interface, or array"))) + (if (eq? exp 'null) + (format "Attempted to call method ~a directly on null. The null value does not have any methods." n) + (format "Attempted to call method ~a on ~a which does not have methods. ~nOnly values with ~a types have methods" + n t + (case level + ((beginner intermediate) "class or interface") + (else "class, interface, or array")))) n src))) ;no-method-error: symbol symbol type id src -> void diff --git a/collects/profj/error-messaging.ss b/collects/profj/error-messaging.ss index d85d68bbc6..ca7805000a 100644 --- a/collects/profj/error-messaging.ss +++ b/collects/profj/error-messaging.ss @@ -9,8 +9,10 @@ ;make-error: 'a string 'a src -> void (define (make-error-pass parm) - (lambda (kind message so src) - (raise-syntax-error 'Error #;kind message (make-so so src parm)))) + (lambda (_ message syn-obj src) + (raise (make-exn:fail:syntax (string->immutable-string message) + (current-continuation-marks) (list-immutable (make-so syn-obj src parm)))))) + ;make-so: symbol src (-> location) -> syntax-object (define (make-so id src parm) diff --git a/collects/tests/profj/advanced-tests.ss b/collects/tests/profj/advanced-tests.ss index f446072054..449a308896 100644 --- a/collects/tests/profj/advanced-tests.ss +++ b/collects/tests/profj/advanced-tests.ss @@ -4,6 +4,12 @@ (prepare-for-tests "Advanced") ;;Execution tests without errors + + (interact-test + 'advanced + '("null.m()") + '(error) + "Calling a method on null") (execute-test "public class Something {