> On Jun 25, 2016, at 6:25 PM, 'John Clements' via Racket Users 
> <[email protected]> wrote:
> 
>> On Jun 24, 2016, at 1:15 PM, Alex Knauth <[email protected]> wrote:
>> 
>>> On Jun 24, 2016, at 1:13 PM, 'John Clements' via Racket Users 
>>> <[email protected]> wrote:
>>> 
>>> I was in the middle of editing a TR file, and I got this error:
>>> 
>>> ../../racket/racket/share/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:270:0:
>>>  Internal Typechecker Error: contract-def-property: thunk called too early
>>> This should only be called after the type-checking pass has finished.
>>> while typechecking:
>>> here
>>> originally:
>>> here

> Here’s a file that triggers this error. I haven’t made any attempt to minify 
> it. You’ll have to install the ‘yaml’ package first. Compiling it with raco 
> make typed-yaml.rkt signals this error:

> <typed-yaml.rkt><signature.asc>


Oh, this is interesting. This bug is happening because the type checker doesn't 
look in dead code, but the contract generation pass is still expecting it to 
supply a type for the expression.

This causes the same thing:

#lang typed/racket
(cond [#false (cast 1 Integer)]
      [else 2])

That explains why it went away when you edited further, because as you edited 
it you fixed the condition so that it wasn't dead code.

Now the question is what to do about it. Should we generate an `any-wrap/c` 
contract in these cases? Or should the type-checker traverse dead code 
specifically looking for the casted-expr property?

Alex Knauth

>> What happens is, a `cast` expression generates a lifted definition to be 
>> filled in later with a contract, and it also generates a casted-expr syntax 
>> property that the type checker will look for later.
>> 
>> When the type checker finds it, it finds the original type of the casted 
>> expression, and puts it in a table so that the contract-generation pass can 
>> look up that type later. Then the contract-generation pass calls a thunk 
>> that looks up the type in the table, and generates a contract for it. If 
>> someone tries to call the contract-generation code before type checking has 
>> finished, that's a bug, and it triggers that error.


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to