Skip to content

class-field-accessor and contracts on fields #1487

@rfindler

Description

@rfindler

TR needs to block field access to fields that aren't listed in the type when a value flows from a typed to an untyped context. Unfortunately, class-field-accessor evades the checking in this contract.

#lang racket
(require typed-racket/utils/opaque-object)

(define c%
  (class object%
    (define/public (m x) x)
    (field [f 1])
    (super-new)))

(define o
  (contract
   (object/c-opaque
    (m (-> any/c integer? integer?)))
   (new c%)
   'pos 'neg))

((class-field-accessor c% f) o) ;; => 1

It is also a problem with object/c itself:

#lang racket

(define c%
  (class object%
    (define/public (m x) x)
    (field [f 1])
    (super-new)))

(define o
  (contract
   (object/c
    (field [f none/c])
    (m (-> any/c integer? integer?)))
   (new c%)
   'pos 'neg))

((class-field-accessor c% f) o) ;; => 1

I noticed this because a new version of object/c doesn't have this bug and Color% doesn't have the s-immutable? field (but the type should) so the new version of object/c triggers a runtime error when opening the "Insert Large Letters..." dialog.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions