racket / racket/typed-racket

Weird typed class typechecking behaviors

Open
#477 2 comments 0 reactions 1 assignee View on GitHub

@takikawa is already working on this.

Since Dec 24, 2016.

Dominant language
Racket
Stars
575
Forks
106
Avg merge
2h 1m
Merged PRs (30d)
2

Description

What version of Racket are you using?

Racket 6.7

What program did you run?
#lang typed/racket/gui

(define-type Separator separator)
(define-type StyleSheet stylesheet)
(define-type Subject subject)

(define-type Contract-Violation-Separator%
  (Class #:implements Canvas%
         (init-field [parent (Instance Area-Container<%>)]
                     [css StyleSheet]
                     [parents (Listof Subject)]
                     [inherits (Option HashTableTop)])))

(define-type Type-Blind-Separator%
  (Class #:implements Canvas%
         (init-field [parent (Instance Area-Container<%>)]
                     [css StyleSheet])))

(struct stylesheet () #:transparent)
(struct subject () #:transparent)
(struct separator ([width : Positive-Byte] [color : String]) #:transparent)

(define separator-filter : (-> Separator) (lambda [] (separator 4 "Snow")))
(define css-cascade : (-> (Listof StyleSheet) (Listof Subject) (-> Separator) (Option HashTableTop) (Values Separator HashTableTop))
  (lambda [stylesheets subjects filter inherits]
    (values (filter) (or inherits (make-hasheq)))))
(define hline% : Contract-Violation-Separator%
  (class canvas%
    (init-field parent css parents inherits)
    
    (: hs Separator)
    (define-values (hs _) (css-cascade (list css) (cons (subject) parents) separator-filter inherits))

    (super-new [parent parent]
               [style null] [paint-callback void] [label #false] [gl-config #false] [enabled #true]
               [vert-margin 0] [horiz-margin 0] [min-width #false] [stretchable-width #true]
               [min-height (separator-width hs)] [stretchable-height #false])
   
(send this set-canvas-background (make-object color% (separator-color hs)))))

The hline% should have been the main issue, however in this example it works well. But
I met it before in a different situation in real world code

static-contracts/instantiate.rkt. car: contract violation.

I still not sure how to reproduce it consistently. During the process of trying to reproduce it, I found another issue fantastically:

(define vline% : Type-Blind-Separator%
  (class canvas%
    (init-field parent css)

    (: hs Separator)
    (define-values (hs _) (css-cascade (list css) (list (subject)) separator-filter #false))
   
    (super-new [parent parent]
               [style null] [paint-callback void] [label #false] [gl-config #false] [enabled #true]
               [vert-margin 0] [horiz-margin 0] [min-width #false] [stretchable-width #true]
               [min-height (separator-width hs)] [stretchable-height #false])
  
 (send this set-canvas-background (make-object color% (separator-color hs)))))

Type Checker: missing type for identifier;
consider adding a type annotation with `:'
identifier: self6196653 in: css


There also are other strange behaviors if the code exists in class body. Some are not reasonable; Some are easy to work around, some are heavily affected by context.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.