Serialize constraints in types (literal arguments still not supported)
This involved, in part, changing the ast::def type so that a def_fn has a "purity" field. This lets the typechecker determine whether functions defined in other crates are pure. It also required updating some error messages in tests. As a test for cross-crate constrained functions, I added a safe_slice function to std::str (slice(), with one of the asserts replaced with a function precondition) and some test cases (various versions of fn-constraint.rs) that call it. Also, I changed "fn" to "pred" for some of the boolean functions in std::uint.
This commit is contained in:
parent
3b6d94d489
commit
7fb35ecf84
15 changed files with 147 additions and 113 deletions
9
src/test/compile-fail/fn-constraint.rs
Normal file
9
src/test/compile-fail/fn-constraint.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// error-pattern: Unsatisfied precondition constraint (for example, le(a, b)
|
||||
use std;
|
||||
import std::str::*;
|
||||
|
||||
fn main() {
|
||||
let uint a = 4u;
|
||||
let uint b = 1u;
|
||||
log_err (safe_slice("kitties", a, b));
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// -*- rust -*-
|
||||
// error-pattern: impure function
|
||||
// error-pattern: Pure function calls function not known to be pure
|
||||
|
||||
fn g() -> () {}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// error-pattern: Constraint args must be
|
||||
|
||||
fn f(int q) -> bool { ret true; }
|
||||
pred f(int q) -> bool { ret true; }
|
||||
|
||||
fn main() {
|
||||
// should fail to typecheck, as pred args must be slot variables or literals
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue