Skip to content

Better error message for misuse of row polymorphic types and add documentation for (All (r #:row) body) #1146

Open
@capfredf

Description

@capfredf

What version of Racket are you using?

Racket 8.2.0.8

What program did you run?


(: hi (All (r #:row)
           (-> r r)))
(define (hi a)
  a)

What should have happened?

The type checker should reject the program, because a type variable for a polymorphic row type is in fact only allowed to appear in (Class #:row-var _) in Typed Racket.

If you got an error message, please include it here.

No error message. But the type checker does not produce useful error messages when hi is called, e.g.:
(hi 10)
===>

Type Checker: Polymorphic function `hi' could not be applied to arguments:
Argument 1:
  Expected: r
  Given:    Positive-Byte

Result type:     r
Expected result: AnyValues

Calling hi with a class type causes an internal error (with PLT_TR_CONTRACT enabled)

(define cls1
  (class object%
    ; Note the missing `super-new`
    (init-field [x : Real 0] [y : Real 0])
    (super-new)))

(hi cls1)

===>

check-below: contract violation
  expected: (or/c Type? tc-results/c)
  given: (Row (list (list 'x Real #t) (list 'y Real #t)) (list (list 'x Real) (list 'y Real)) '() '() #f)
  in: the t argument of
      (->i
       ((s
         (t)
         (if (Type? t)
           (-or/c full-tc-results/c Type?)
           full-tc-results/c))
        (t (or/c Type? tc-results/c)))
       (_
        (t)
        (if (Type? t) Type? full-tc-results/c)))
  contract from: 
      <pkgs>/typed-racket-lib/typed-racket/typecheck/check-below.rkt
  blaming: <pkgs>/typed-racket-lib/typed-racket/typecheck/tc-app-helper.rkt
   (assuming the contract is correct)
  at: <pkgs>/typed-racket-lib/typed-racket/typecheck/check-below.rkt:20:2

lack of documentation how to define polymorphic row types

It seems the documentation for (All (r #:row) body) is missing

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions