-
Notifications
You must be signed in to change notification settings - Fork 262
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
Fix: Optional pre-type won't cause a crash anymore #5442
Conversation
@@ -583,6 +583,8 @@ public enum CommonConfirmationBag { | |||
preType = preType.Normalize(); | |||
if (preType is PreTypeProxy) { | |||
return false; | |||
} else if (preType is UnusedPreType) { |
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.
Can you add a comment to the class UnusedPreType
?
@@ -455,6 +455,9 @@ public class PreTypePlaceholderModule : PreTypePlaceholder { | |||
public class PreTypePlaceholderType : PreTypePlaceholder { | |||
} | |||
|
|||
/// Currently used exclusively for assigning a pre-type to MemberSelect expressions, such as "obj.method", | |||
/// which is not considered an expression. This indicates that resolution has occurred, |
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.
What do you mean by MemberSelect
not being considered an expression? It inherits from Expression
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.
It weirdly is an Expression, but not a true Dafny expression: you cannot use it in a regular Dafny expression. Consider the following:
class A {
method Test() {
}
}
method Main() {
var a := new A();
var f := a.Test; // Error, expected a Dafny expression on the RHS
f();
}
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.
It is also used for fields, in which case it is an expression, right?
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.
It seems nice to conceptually consider a MemberSelectExpr
that references a method still an expression, even if we don't allow it in an expression context. If we do that, then I would expect to assign some sort of callable type to it. Could we rename UnusedPreType
to Method[Pre]Type
?
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.
Yes, it's used for fields and in that case it's indeed an expression.
I did the renaming, hoping it won't break any future development.
@@ -583,6 +583,8 @@ public enum CommonConfirmationBag { | |||
preType = preType.Normalize(); |
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.
Can you add a comment to ConfirmConstraint
, or update its signature (parameter names) to make it clear what it does? I don't understand the meaning of the parameters or return value by looking at just its signature and comment.
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.
I can't, as I don't understand the code at a level high enough to do that. I don't have a mental model of what ConfirmConstraint does, nor about what code context it was called with. I'll leave it for @RustanLeino to comment on it.
I don't think this is the right fix. Looking at the input program:
I think the expect file should be:
and nothing else. I think these errors some come from the pretype resolution phase and leave a preTypeProxy assigned as the type of I've pushed a commit to this PR that almost achieves what I describe above. The errors are now:
and nothing else from |
Thank you very much for this more precise fix ! Looks great. |
This PR fixes #5369
I added the corresponding test.
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.