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

x?.y works even when x is not an optional #387

Closed
kach opened this issue Aug 8, 2018 · 4 comments
Closed

x?.y works even when x is not an optional #387

kach opened this issue Aug 8, 2018 · 4 comments
Labels
Type: Bug 🐛 Something isn't working

Comments

@kach
Copy link
Contributor

kach commented Aug 8, 2018

Because of the way ?. is implemented, things like this happen:

ergo$ return {a: 1}?.a;
Response. none
  :  {emit: Unit[], response: Nothing?, state: Unit}?

(This should be a type error, I think, because people will surely try to do this and get confused.)

@jeromesimeon
Copy link
Member

I agree. I seem to recall this is the semantics in Swift which I started from, but I don't like it.

@kach
Copy link
Contributor Author

kach commented Aug 8, 2018

Can be compiled to (let $opt : Any? = <operand> ; match …), where the let just forces the operand to be of an optional type.

@kach kach added the Type: Bug 🐛 Something isn't working label Aug 8, 2018
@jeromesimeon
Copy link
Member

Looking at the example more carefully, this is definitely not the semantic in Swift. It's certainly a bug.

@jeromesimeon
Copy link
Member

Addressed in #502 :

ergo$ return {a: 1}?.a
Compilation error (at line 1 col 7). Cannot match unless against an option type
return {a: 1}?.a
       ^^^^^^^^^
ergo$ return 1?.a
Compilation error (at line 1 col 7). Cannot match unless against an option type
return 1?.a
       ^^^^
ergo$ return some({a:1})?.a
Response. some(1) : Integer?
ergo$ return none?.a
Response. none : Nothing?
ergo$ let x : {a:Integer}? = none; return x?.a
Response. none : Integer?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants