Skip to content
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

Type error when @extern method's result widens ADT value #1537

Open
vkuncak opened this issue Jun 21, 2024 · 2 comments
Open

Type error when @extern method's result widens ADT value #1537

vkuncak opened this issue Jun 21, 2024 · 2 comments
Assignees

Comments

@vkuncak
Copy link
Collaborator

vkuncak commented Jun 21, 2024

This:

import stainless.annotation.*
object Branching:

  sealed trait Tree
  case class Node() extends Tree

  extension (tree: Tree)
    def nodesGood: Boolean = true

  @extern
  def myTree1: Tree = {
    Node()    
  } ensuring(_.nodesGood)
    
end Branching

gives:

[  Info  ] Preprocessing the symbols...                             
[ Error  ] TypeCheckBug.scala:11:23: Type error: {
[ Error  ]   <empty tree>[Tree]
[ Error  ] } ensuring {
[ Error  ]   nodesGood
[ Error  ] }, expected Tree,
[ Error  ] found <untyped>
[ Error  ] 
[ Error  ] Typing explanation:
[ Error  ] {
[ Error  ]   <empty tree>[Tree]
[ Error  ] } ensuring {
[ Error  ]   nodesGood
[ Error  ] } is of type <untyped>
[ Error  ]   <empty tree>[Tree] is of type Tree
[ Error  ]   nodesGood is of type (Node) => Boolean
[ Error  ]     nodesGood(_$1) is of type Boolean
[ Error  ]       _$1 is of type Node because nodesGood was instantiated with  with type (Tree) => Boolean
             def myTree1: Tree = {
                                 ^...
[ Fatal  ] Well-formedness check failed after extraction

in Stainless Version: 0.9.8.7-14-g7fd69e2

@vkuncak
Copy link
Collaborator Author

vkuncak commented Jun 21, 2024

The workaround is to explicitly type the result of the closure given to ensuring ,

  @extern
  def myTree1: Tree = {
    Node()    
  } ensuring((res: Tree) => res.nodesGood)

@mario-bucev
Copy link
Collaborator

Or explicitly widen the resulting expression:

@extern
def myTree1: Tree = {
  Node() : Tree
} (_.nodesGood)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants