Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Type checking for pattern matching against optionals #502

Closed
jeromesimeon opened this issue Jan 8, 2019 · 2 comments
Closed

Type checking for pattern matching against optionals #502

jeromesimeon opened this issue Jan 8, 2019 · 2 comments

Comments

@jeromesimeon
Copy link
Member

It's unclear that any of those should be allowed:

$ return match 1 with let? x then 1 else 0
Response. 0 : Integer
$ return match 1 with let? x then x else 0
Response. 0 : Integer
$ return 1 ?? 0
Response. 0 : Integer
$ define concept A{x:String}
$ return match A{x:"foo"} with let? x: A then x else 0
Response. 0 : Any
$ return 1?.a
Response. none : Nothing?
$ return {a: 1}?.a
Response. none : Nothing?

Although one could argue that this is a reasonable semantics, I think one could make a case that pattern matching should work on types consistent with the pattern (with let x? only for option types, with let x : B only for classes, with let x = 1 only for Integer, etc.).

Note that if considering e1 ?? e2 to be syntactic sugar / consistent with pattern matching, then issue #387 argue that optional matching against a non-optional type should be an error.

@jeromesimeon
Copy link
Member Author

Proposed resolution is to change the type checker for let? x pattern matching to raise a type error for non-optional types.

@jeromesimeon
Copy link
Member Author

Addressed in #503

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant