# Surprising (?) type error

**URL:** https://racket.discourse.group/t/surprising-type-error/2110
**Category:** Questions & Answers
**Created:** [July 18, 2023, 1:53am UTC](https://racket.discourse.group/t/surprising-type-error/2110 "2023-07-18T01:53:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bkc39](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bkc39/32/944_2.png) [@bkc39](https://racket.discourse.group/u/bkc39)
#### Post date: [July 18, 2023, 1:53am UTC](https://racket.discourse.group/t/surprising-type-error/2110/1 "2023-07-18T01:53:44Z")

</div>

I have been going through the typed/racket guide and encountered code like the following

```scheme
#lang typed/racket

(: prop:foo (Struct-Property (-> Self Number)))
(: foo-pred (-> Any Boolean : (Has-Struct-Property prop:foo)))
(: foo-get (-> (Has-Struct-Property prop:foo)
               (Some (X)
                     (-> X Number)
                     : #:+ X)))
(define-values (prop:foo foo-pred foo-get)
  (make-struct-type-property 'foo))

(struct Num ([n : Number])
  #:property prop:foo
  (lambda ([me : Num])
          : Number
    (Num-n me)))

(: num/foo Number)
(define num/foo
  (let ([a1 : Num
            (Num 42)])
    ((foo-get a1) a1)))

(module+ test
  (require typed/rackunit)
  ;; succeeds
  (check-equal? num/foo 42))

```

However, The following form leads to a type error

```scheme
;; type error
(module+ test
  (check-equal?
   (ann
    (let ([a1 : Num
              (Num 42)])
      ((foo-get a1) a1))
    Number)
   42))

```

It fails with the following error:

```scheme
Type Checker: type mismatch
  expected: (B 0)
  given: Num
  in: a1

```

This code should be equivalent if my understanding is correct, it just inlines the body in the definition of `num/foo` and includes the appropriate inline annotation similar to the one on the top level `define` for `num/foo`. Can someone explain to me why the first test form succeeds and the second is a type error? Thanks

---

<div class="post-metadata">

### Author: ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)
#### Post date: [July 18, 2023, 4:58pm UTC](https://racket.discourse.group/t/surprising-type-error/2110/2 "2023-07-18T16:58:42Z")

</div>

Interestingly enough, this works:

```plaintext
(module+ test
  (let ([a1 : Num (Num 42)])
    (define xxx (foo-get a1))
    (check-equal? (xxx a1) 42)))

```

I suggest opening an issue w/ Typed Racket.
