Skip to content

Function precondition not maintained for subsequent calls #862

Closed

Description

@brson

Similar to #694:

pred p(j: int) -> bool { true }

fn f(i: int, j: int) : p(j) -> int { j }

fn g(i: int, j: int) : p(j) -> int { f(i, j) }
../src/test/run-pass/typestate.rs:8:37:8:44: error: Unsatisfied precondition constraint (for example, p(j)[../src/test/run-pass/typestate.rs:6:23:6:27]) for expression:
f(i, j)
Precondition:
p(j)[../src/test/run-pass/typestate.rs:6:23:6:27], init(j [../src/test/run-pass/typestate.rs:8:0:8:46]), init(i [../src/test/run-pass/typestate.rs:8:0:8:46])
Prestate:
!p(j)[../src/test/run-pass/typestate.rs:6:23:6:27], p(i, j)[../src/test/run-pass/typestate.rs:8:23:8:27], init(j [../src/test/run-pass/typestate.rs:8:0:8:46]), init(i [../src/test/run-pass/typestate.rs:8:0:8:46]), !init(g [../src/test/run-pass/typestate.rs:8:0:8:46]), !init(g! [../src/test/run-pass/typestate.rs:8:0:8:46])
../src/test/run-pass/typestate.rs:8 fn g(i: int, j: int) : p(j) -> int { f(i, j) }

This problem is affecting std::str::replace

Activity

  1. catamorphism commented on Sep 1, 2011

    @catamorphism
    Contributor

    It was actually worse than that -- any typestate constraints that weren't of the form p(x1, x2, ..., xn) on a function decl of the form f(x1:t1, x2:t2, ..., xn:tn) weren't working. Fix coming up.

  2. added a commit that references this issue on Dec 12, 2017
  3. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions