Skip to content

Commit 88d616d

Browse files
committed
cleaning and testing
1 parent 5f27658 commit 88d616d

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

macros/disabled.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ let import = macro {
123123
raiseBlame(blame.swap().addExpected('value to not be manipulated').addGiven('called Object.hasOwnProperty on property ' + propName).addLocation(locationMsg));
124124
},
125125
get: function (target, propName) {
126-
raiseBlame(blame.swap().addExpected('value to not be manipulated').addGiven('performed obj.' + propName).addLocation(locationMsg));
126+
var givenMsg = 'performed obj.' + propName;
127+
if (propName === 'valueOf') {
128+
givenMsg = 'attempted to inspect the value';
129+
}
130+
raiseBlame(blame.swap().addExpected('value to not be manipulated').addGiven(givenMsg).addLocation(locationMsg));
127131
},
128132
set: function (target, propName, val$2) {
129133
raiseBlame(blame.swap().addExpected('value to not be manipulated').addGiven('performed obj.' + propName + ' = ' + val$2).addLocation(locationMsg));

macros/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ let import = macro {
123123
raiseBlame(blame.swap().addExpected('value to not be manipulated').addGiven('called Object.hasOwnProperty on property ' + propName).addLocation(locationMsg));
124124
},
125125
get: function (target, propName) {
126-
raiseBlame(blame.swap().addExpected('value to not be manipulated').addGiven('performed obj.' + propName).addLocation(locationMsg));
126+
var givenMsg = 'performed obj.' + propName;
127+
if (propName === 'valueOf') {
128+
givenMsg = 'attempted to inspect the value';
129+
}
130+
raiseBlame(blame.swap().addExpected('value to not be manipulated').addGiven(givenMsg).addLocation(locationMsg));
127131
},
128132
set: function (target, propName, val$2) {
129133
raiseBlame(blame.swap().addExpected('value to not be manipulated').addGiven('performed obj.' + propName + ' = ' + val$2).addLocation(locationMsg));

src/contracts.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,13 @@
183183
},
184184

185185
get: function(target, propName) {
186+
var givenMsg = "performed obj." + propName;
187+
if (propName === "valueOf") {
188+
givenMsg = "attempted to inspect the value";
189+
}
186190
raiseBlame(blame.swap()
187191
.addExpected("value to not be manipulated")
188-
.addGiven("performed obj." + propName)
192+
.addGiven(givenMsg)
189193
.addLocation(locationMsg));
190194
},
191195
set: function(target, propName, val) {

test/test_contracts.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,53 @@ in: in the type variable a of
575575
function foo guarded at line: 562
576576
blaming: (calling context for foo)
577577
`
578-
})
578+
});
579+
580+
it("should catch odds as not a polymorphic function", function() {
581+
@ forall a ([...a]) -> [...a]
582+
function odds(l) {
583+
return l.filter(function(x) {
584+
return x % 2 !== 0;
585+
});
586+
}
587+
588+
blame of {
589+
odds([1,2,3,4]);
590+
} should be `odds: contract violation
591+
expected: value to not be manipulated
592+
given: 'attempted to inspect the value'
593+
in: in the type variable a of
594+
the 0th field of
595+
the 1st argument of
596+
([....a]) -> [....a]
597+
function odds guarded at line: 582
598+
blaming: function odds
599+
`
600+
});
601+
602+
it("should work with function of more than one type variable", function() {
603+
@ forall a, b, c (a, b, (a, b) -> c) -> c
604+
function foo(x, y, f) { return f(x, y); }
605+
606+
(foo(1, 2, function(x, y) { return x + y; })).should.equal(3);
607+
608+
@ forall a, b, c (a, b, (a, b) -> c) -> c
609+
function bad_foo(x, y, f) {
610+
f(x, y);
611+
return 100;
612+
}
579613

614+
blame of {
615+
bad_foo(1, 2, function(x, y) { return x + y; })
616+
} should be `bad_foo: contract violation
617+
expected: an opaque value
618+
given: 100
619+
in: in the type variable c of
620+
the return of
621+
(a, b, (a, b) -> c) -> c
622+
function bad_foo guarded at line: 609
623+
blaming: function bad_foo
624+
`
625+
})
580626

581627
});

0 commit comments

Comments
 (0)