-
Notifications
You must be signed in to change notification settings - Fork 43
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
AdtPlugin java.lang.ClassCastException #581
Comments
I did a bit of investigation. I was not able to resolve it yet, but here is some additional information about the underlying issue. The silver/src/main/scala/viper/silver/parser/Translator.scala Lines 369 to 376 in 5503e4a
and errors here on line 586: silver/src/main/scala/viper/silver/parser/Translator.scala Lines 583 to 586 in 5503e4a
This is because the silver/src/main/scala/viper/silver/plugin/standard/adt/AdtPlugin.scala Lines 132 to 137 in 5503e4a
The tricky part here is, that it needs a I'm not sure how to best tackle this. With some help I may be able to do it. One idea I have left after playing around a bit is to encode both the |
Actually, after sleeping on it for a night, I think I have a nicer idea: I can just translate the |
I created PR #582 for a quick fix for some corner cases, however, this is not a sufficient fix yet. For example, this program still crashes:
but with a different error:
So far I still think that creating a custom |
I have some extra information to share that was accumulated during a Zulip discussion with Alex Summers: Ideally, when the transformer here: silver/src/main/scala/viper/silver/plugin/standard/adt/AdtPlugin.scala Lines 110 to 129 in 5503e4a
reaches the case pf@PFunction(idndef, formalArgs, typ, pres, posts, body) =>
PFunction(
idndef,
formalArgs map transformStrategy,
transformStrategy(typ), // transforms the PDomainType to PAdtType
pres map transformStrategy,
posts map transformStrategy,
body map transformStrategy
)(pf.pos) Even when adding this case for case pr@PResultLit() => {
// find function and check that its return type was updated
var par: PNode = pr.parent.get
while (!par.isInstanceOf[PFunction]) {
if (par == null) sys.error("cannot use 'result' outside of function")
par = par.parent.get
}
par match {
case pf@PFunction(idndef, formalArgs, typ@PDomainType(idnuse, args), pres, posts, body) if declaredAdtNames.exists(_.name == idnuse.name) =>
throw new Exception("not transformed: " + pr + " | " + pf)
}
PResultLit()(pr.pos) The weird part is, that even though the function return type is properly replaced during the Might this be an issue with the transformation code itself? |
This hack seems to work for most corner cases: silver/src/main/scala/viper/silver/plugin/standard/adt/AdtPlugin.scala Lines 122 to 136 in 2fe26fb
However, this does not solve the corner case from this comment, still. I'm hoping that there is a better solution that fixes the transformer so that all corner cases work without any hacks, although unfortunately I was unable to spot it so far :) |
Hello! I found my way here through doing some research for Prusti and I noticed the ADT plugin got merged very recently :) This looks like a really great feature, thank you for adding it! I set my Viper IDE to
nightly
and took it for a spin. I managed to break something when adding a post-condition that mentions a returned ADT:This results in the error:
Everything seems to work for pre-conditions okay, as far as I can tell this error is only triggered by a post-condition that mentions an ADT
result
. I suspect this corner case was missed when translating from the Parser AST to the Viper AST.The text was updated successfully, but these errors were encountered: