-
Notifications
You must be signed in to change notification settings - Fork 424
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
Workaround an issue preventing users to catch errors from #26656
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Engin Kayraklioglu <[email protected]>
@@ -1185,7 +1185,12 @@ module JSON { | |||
proc fromJson(jsonString: string, type loadAs): loadAs throws { |
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.
Could you add a warning to the docs about this requirement? Or maybe a compilerWarning
guarded by !isDefaultInitializable(loadAs)
?
Hmm... it appears that this PR added a test in which the type is not default-initializable. I don't know immediately why a simple-looking (And that test is the only one that breaks on this branch) |
I think it's not default-initializable because it's non-nilable |
That was my assumption, but I couldn't really rationalize it. Default-initializability should be about the fields of the base type and not about the modifiers applied to it. But I haven't thought too deeply. Do you have a rationale in mind? |
I think the ultimate answer here is that this is just how we've designed the language. You can't write something like To rationalize it, by not indicating a class as nilable, we are asserting that it will always be a value of an initialized class. That initialization has to come from somewhere, and we don't default-initialize class instances. |
It looks like there are two alternatives here, then:
Assuming that this is already in the bug category to me, (2) seems that it can reduce the impact of the bug. I can create a bug report for the remaining case where the type is non-default-initializable. Does that make sense? That would be addressing your inline comment in a slightly different way, as well. |
I think something in the docs would be good, otherwise I'm fine with this going in. If you make a bug report, can you assign it to me? I've been trying to think of ways to improve the situation here, but nothing so far. Perhaps I could figure something out for records, but classes complicate things quite a bit. |
JSON.fromJson
used the pattern:this results in calling a compiler-generated deserialization initializer that does not throw. While working on Arkouda checkpointing that led to writing code in which there are uncatchable errors. I worked this around in Arkouda for the time being by having my own
fromJson
-like helper.This PR adjusts the standard
fromJson
to use the following pattern, from which an error can be thrown and caught as expected:Test: