racket / rackunit

Other
18 stars 34 forks source link

TR + check-equal? before (require rackunit) causes error #155

Closed jbclements closed 2 years ago

jbclements commented 2 years ago

This file

#lang typed/racket/base

(module+ test
  (check-equal? 1234 1234)
  (require typed/rackunit))

now fails, with this error:

ouch.rkt:4:2: Type Checker: No function domains matched in function application:
Domains: Any Any String 
         Any Any 
Arguments: (Listof Any)

  in: (check-equal? 1234 1234)
  location...:
   ouch.rkt:4:2
  context...:
   /Users/clements/racket/racket/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:414:0: type-check
   /Users/clements/racket/racket/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:653:0: tc-module
   /Users/clements/racket/racket/share/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:101:12
   /Users/clements/racket/racket/share/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:22:4

See #153

Originally posted by @jbclements in https://github.com/racket/rackunit/issues/153#issuecomment-1043384124

samth commented 2 years ago

Here's a simpler program with the same error:

#lang typed/racket/base

(require typed/rackunit)
(#%app check-equal? 1234 1234)
jbclements commented 2 years ago

Arguably even simpler:

#lang typed/racket

(require typed/rackunit)

check-equal?

with output:

Type Checker: No function domains matched in function application:
Domains: Any Any String 
         Any Any 
Arguments: (Listof Any)
 in: #%module-begin
jbclements commented 2 years ago

The macro stepper suggests that this expands to

(#%plain-module-begin
 (#%require typed/rackunit)
 (#%expression
  (lambda args
    (#%app
     (let-values (((...ed/rackunit/main.rkt:26:14) check-equal?-imp1)
                  ((temp1) '(3-unsaved-editor 5 0 47 12))
                  ((temp2) 'chk))
       (#%app
        (#%app
         checked-procedure-check-and-extract
         struct:keyword-procedure
         ...ed/rackunit/main.rkt:26:14
         keyword-procedure-extract
         '(#:expression #:location)
         (quote 2))
        '(#:expression #:location)
        (#%app list temp2 temp1)))
     args))))

... just before it signals the error.

jbclements commented 2 years ago

This could be as easy as changing a hash-quote into a hash-quote-splice somewhere.

jbclements commented 2 years ago

Opinions, @samth ?

samth commented 2 years ago

@capfredf and I talked about this. The problem is that the application features keyword arguments which the TR type doesn't expect. It's not clear why that application has the same keyword arguments as the inner application, so that requires more investigation.

jbclements commented 2 years ago

Many thanks. My apologies for dragging this forward by merging this PR prematurely.