-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
require type checking on CustomConst
#325
Conversation
this now makes it impossible for use of static values of types from resources that do not provide binary `CustomConst`. Is this what we want?
15bc0c2
to
102fef1
Compare
src/ops/constant.rs
Outdated
// TODO it would be good to ensure that this is a *classic* CustomType not a linear one! | ||
fn custom_type(&self) -> CustomType; | ||
/// Check the value is a valid instance of the provided type. | ||
fn check_type(&self, typ: &CustomType) -> Result<(), ConstTypeError>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - so the I-have-some-YAML implementation of this (maybe there are two such: one which embeds a type, one without - I mean the one with) says:
if typ == myEmbeddedType {Ok(())} else {Err(....)}
right?
You could make this return String for errors, and then wrap those in CustomCheckFail when we call this? It'd make it clear whose code an error was coming from...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
part one: yes
part two: yes, but with some wrapping i think, will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah no actually, CustomCheckFail is only there as a catch all in case the existing error modes don't match up, in most cases ValueCheckFail
is the correct mode and can be reused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's no way for a CustomConst to synthesize its type, there's no way to tell that a CustomConst is Hashable or otherwise. If we don't want to add a synthesizing method, do we want to add a method returning a TypeTag
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need such (#322 will work without), but that doesn't mean we shouldn't have it ;). I guess it could return Option, and maybe should, whereupon we can't rely on it, so it doesn't reduce complexity (we still have to handle all the cases).
Well, they can use serde_yaml, right? At present that probably doesn't all work, but that'll come shortly, I think the next PR after this. And how was it possible to have static values w/out binary
Thing is that if we don't have a So I think it is, but I haven't really understood the drawback, or the alternative. This may be better to go in after #322, tho. |
On the error type (continued from #325 (comment)). The thing is that At the same time, it's also one of the most informative (perhaps alongside TypeMismatch), in that it does at least tell you which part of the value/type didn't match up. But really, this is available in all cases (it's the So, ideally, I'd like to see every message include the value and type, so ValueCheckFailed really is then "no further information". Whether we do that by adding value+type to each, or by structuring ConstTypeError differently (maybe as a struct, value + type + "enum FurtherDetails"), or what, I don't know. But that's not for this PR. In this PR, well, I think it would be strange for an The situation where this fails I guess is if your |
string custom type check error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks. I like struct CustomCheckFail
!
Happy for you to remove ConstTypeError::TypeMismatch too
Closes #318