diff --git a/typed-racket-lib/typed-racket/typecheck/error-message.rkt b/typed-racket-lib/typed-racket/typecheck/error-message.rkt index c0fd1145..bbac5e2c 100644 --- a/typed-racket-lib/typed-racket/typecheck/error-message.rkt +++ b/typed-racket-lib/typed-racket/typecheck/error-message.rkt @@ -51,6 +51,11 @@ ;; prints the binding locations of each type variable. (type-mismatch (format "`~a'" t1) (format "a different `~a'" t2) "type variables bound in different scopes")] + [((Struct: n1 _ _ _ _ _) (Struct: n2 _ _ _ _ _)) + #:when (and (not (free-identifier=? n1 n2)) + (eq? (syntax-e n1) (syntax-e n2))) + (type-mismatch (syntax-e n1) (format "a different ~a" (syntax-e n2)) + "incompatible struct types with the same name")] [((? Class?) (? Class?)) (class-mismatch r1 r2)] [((Instance: (app resolve (? Class? c1))) (Instance: (app resolve (? Class? c2)))) diff --git a/typed-racket-test/fail/same-name-struct-type.rkt b/typed-racket-test/fail/same-name-struct-type.rkt new file mode 100644 index 00000000..0f094499 --- /dev/null +++ b/typed-racket-test/fail/same-name-struct-type.rkt @@ -0,0 +1,20 @@ +#; +(exn-pred #rx"incompatible struct types with the same name") +#lang racket/load + +;; Test the error message for subtyping errors on struct types +;; with the same name + +(module a typed/racket + (struct foo ([x : Integer])) + (define a-foo (foo 3)) + (provide a-foo)) + +(module b typed/racket + (struct foo ([x : String])) + (define (f [a-foo : foo]) (foo-x a-foo)) + (provide f)) + +(module c typed/racket + (require 'a 'b) + (f a-foo))