From cf1a2c71d056ff6247e46daf1bfa955a3d7d530f Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Thu, 8 Nov 2012 23:02:37 -0500 Subject: [PATCH] Fix a free variance bug Commit ffe45ecce had introduced a regression with some polymorphic functions imported between typed modules due to miscommunicated variance information. original commit: daca1c0d5b6040978b1c75d4cc822c0a3a819181 --- .../tests/typed-racket/succeed/variance-test.rkt | 16 ++++++++++++++++ collects/typed-racket/rep/free-variance.rkt | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 collects/tests/typed-racket/succeed/variance-test.rkt diff --git a/collects/tests/typed-racket/succeed/variance-test.rkt b/collects/tests/typed-racket/succeed/variance-test.rkt new file mode 100644 index 00000000..63ac07cc --- /dev/null +++ b/collects/tests/typed-racket/succeed/variance-test.rkt @@ -0,0 +1,16 @@ +#lang typed/racket + +;; Test a variance regression + +(struct: (A) Foo ([elems : (Vectorof A)])) + +(: make-foo (All (A) (A -> (Foo A)))) +(define (make-foo x) (Foo (vector x))) + +;; Need a module+ here because this test failed +;; originally when variance information wasn't preserved +;; across modules. +(module+ test + ;; should type check, but won't if the element has + ;; the Any type incorrectly + (+ 1 (vector-ref (Foo-elems (make-foo 1)) 0))) diff --git a/collects/typed-racket/rep/free-variance.rkt b/collects/typed-racket/rep/free-variance.rkt index 8ded52ed..77e5e793 100644 --- a/collects/typed-racket/rep/free-variance.rkt +++ b/collects/typed-racket/rep/free-variance.rkt @@ -46,7 +46,7 @@ (match var ((== Covariant) #'Covariant) ((== Contravariant) #'Contravariant) - ((== Invariant) #'Contravariant) + ((== Invariant) #'Invariant) ((== Constant) #'Constant) ((== Dotted) #'Dotted)))