icerpc / slicec

The Slice compiler library
Apache License 2.0
13 stars 5 forks source link

Bad error message for class field with optional type #577

Closed bernardnormier closed 1 year ago

bernardnormier commented 1 year ago

This is what happens when you give an optional type to a class field:

error E032: optional types are not supported by the Slice1 encoding (except for classes, proxies, and with tags) 
error E032: file encoding was set to Slice1 here

This is obviously not correct. You're writing a class, in an encoding = Slice1 file. The correct suggestion is to add a tag, not change the encoding.

bernardnormier commented 1 year ago

Probably related to #470.

bernardnormier commented 1 year ago

I suspect a difficulty is E032 needs to be split:

src\diagnostics\errors.rs
460:        "E032",
461-        OptionalsNotSupported,
462-        format!("optional types are not supported by the {encoding} encoding (except for classes, proxies, and with tags)"),
463-        encoding

Let's look at different contexts for this error:

BTW the existing message is also incorrect since customs can be optional with Slice1 without tag. But if you typed a valid type, like int32?, it's odd to tell you "I see you want an optional type, you're sure you don't want to use another type?".