Skip to content

Allow outer function outputs in outline preconditions (Fix issue #1029)#1031

Draft
jcp19 wants to merge 3 commits into
masterfrom
claude/allow-return-params-preconditions-4wyE3
Draft

Allow outer function outputs in outline preconditions (Fix issue #1029)#1031
jcp19 wants to merge 3 commits into
masterfrom
claude/allow-return-params-preconditions-4wyE3

Conversation

@jcp19
Copy link
Copy Markdown
Contributor

@jcp19 jcp19 commented May 13, 2026

PR #1018 introduced a regression where occurrences of a return parameter are no longer allowed in pres of outline blocks and closures declared inside the body. This fixes that and introduces new tests

When checking preconditions, we used to reject every reference to an
output parameter, regardless of which function-like construct introduced
it. This was too strict: output parameters of the surrounding function
already have a meaningful value by the time an outline statement or a
nested closure literal is entered, so referencing them in the
precondition of those constructs is legitimate.

The check now only rejects references to output parameters declared by
the spec's own owner (function, method, closure literal, interface
method, or method implementation proof). For outline statements - which
do not declare their own outputs - no output parameter reference is
rejected.

Fixes #1029.
@jcp19 jcp19 marked this pull request as draft May 13, 2026 08:15
Comment on lines +6 to +8
// Output parameters of the surrounding function may be referenced in the
// precondition of an outline statement, because they have a meaningful value
// at the entry of the outline block. (Issue #1029)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Output parameters of the surrounding function may be referenced in the
// precondition of an outline statement, because they have a meaningful value
// at the entry of the outline block. (Issue #1029)
// Output parameters of the surrounding function may be referenced in the
// precondition of an outline statement and closres.

// precondition of an outline statement, because they have a meaningful value
// at the entry of the outline block. (Issue #1029)

ensures acc(r) && *r == 42
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add explicit return statements in all examples

Comment on lines +37 to +45
func bad() {
//:: ExpectedOutput(type_error)
c := requires s == 0
ensures s == 1
func nested() (s int) {
return 1
}
_ = c
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

introduce another example where a closure's precondition mentions the return parameter of the outer scope. that should be accepted by the type checker as well.

Comment on lines +47 to +60
// An outline block in a function without named output parameters keeps
// type-checking.
func unnamedOut() *int {
i@ := 0
p := &i

requires acc(p)
ensures acc(p) && *p == 42
outline (
*p = 42
)

return p
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// An outline block in a function without named output parameters keeps
// type-checking.
func unnamedOut() *int {
i@ := 0
p := &i
requires acc(p)
ensures acc(p) && *p == 42
outline (
*p = 42
)
return p
}

@jcp19 jcp19 changed the title Allow outer function outputs in outline preconditions (Issue #1029) Allow outer function outputs in outline preconditions (Fix issue #1029) May 13, 2026
@jcp19 jcp19 linked an issue May 13, 2026 that may be closed by this pull request
- Reword the header comment to refer to outlines and closures.
- Add explicit return statements in the positive examples.
- Add a positive test case where a nested closure literal's precondition
  references the outer function's named output parameter.
- Drop the redundant outline-with-unnamed-output example.
Comment thread src/test/resources/regressions/issues/001029.gobra Outdated
Comment thread src/test/resources/regressions/issues/001029.gobra Outdated
Co-authored-by: João Pereira <joaopereira.19@gmail.com>
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

Successfully merging this pull request may close these issues.

Precondition of Outline Stmt Rejected

2 participants