sanctuary-js / sanctuary-def

Run-time type system for JavaScript
MIT License
294 stars 23 forks source link

record types do not behave correctly as supertypes #275

Open davidchambers opened 4 years ago

davidchambers commented 4 years ago

This expression erroneously evaluates to true:

$.test ([])
       ($.NullaryType ('X') ('') ([$.RecordType ({x: $.Number})]) (_ => true))
       ({x: null})

The problem is that the supertype membership test uses t._test (env) (x), but a record type's _test method only determines whether the field names are present.

davidchambers commented 2 years ago

This is tricky. The current behaviour is what allows us to underline a particular field of a record type in error messages.

We want strict behaviour in the context of $.test but forgiving behaviour when generating error messages. :thinking: