Dafny context modifies clause error - dafny

i am having a really hard time getting rid of the last error in my Dafny program. Can someone point me in the right direction?
Here is the code: http://rise4fun.com/Dafny/2FPo
I am getting this error: assignment may update an array element not in the enclosing context's modifies clause
I tried adding modifies rectangle in the merge method (even though i am pretty sure that is already included in modifies this) but that just creates a similar error on the merge method call.
I am really lost on this one. Thanks for the help

The problem is that "modifies this" allows modification of the fields of this, not modification of the things pointed to by those fields. In other words, it would be appropriate if the method was doing:
this.rectangles := new_rectangle_array;
but not if it was doing:
this.rectangles[3] := new_rect;
So, in the places you have "modifies this" you should instead have "modifies rectangles".
For a similar reason, Test needs to be annotated with "modifies c.rectangles", not "modifies c".
Finally, to convince Dafny that it's OK to call Test, you need to give the constructor for Couverture a post-condition constraining the rectangles field. Otherwise, the verifier can't be sure that it's OK to call Test: as far as the verifier can tell, couv might contain some random array that Main isn't allowed to modify.
For the full code, see http://rise4fun.com/Dafny/Skrg.

Related

In Lua, why might a function or expression evaluate multiple times in an update call?

Working in Lua and I currently I have a function that does:
function Entity:damage(dmg)
self.health = self.health - dmg
end
when I call it in another class's update function, like so:
function Room:update(dt)
if not entity.dead and self.player:collides(entity) then
self.player:damage(1)
end
instead of only dealing 1 damage, it actually deals up to 13 damage, as if the function is being called multiple times, but I'm not sure why that would be? I have very similar functions that are all doing the same thing and I'm not sure why the function/expression therein is being evaluated multiple times?
I've omitted a lot of code because I'm not sure what is relevant to helping. (I am using a Class library and player inherits from entity)
understandably a lot of code is missing and I'll likely end up debugging this myself, but if anyone has a suggestion that might be helpful/steer me in some direction I'd appreciate it, and I do apologize for the poorly formed question.
Thanks to everyone who commented; with your help, I found out what was going on!
First, Piglet you were correct--the 'collision' check state was longer than 1 frame. However, once I fixed that, I still noticed I was getting the wrong return value for
function Room:update(dt)
if not entity.dead and self.player:collides(entity) then
self.player:damage(1)
end
and I think Alexander you were correct in pointing out the multithreading or upvalues--that is a little bit beyond my comprehension at the moment-- but I checked the page linked and discovered that when I moved the function call 'upstream', I was getting the return value I expected.
So it seems perhaps where I was calling the function resulted in it being called or processed multiple times by the update functions of various classes.
Thanks for the comments; I'll use them to improve my question asking and also my general knowledge :)

How to set a variable using geolocation.getCurrentPosition

This is related to this post, but different in that I am trying to understand why I cannot set an outside variable from inside of geolocation.getCurrentPosition
I can't seem to get any kind of return value from it, and I can't set a value from it. I can only access the position object from inside of it. I have tried passing in this.
I forked derek-朕會功夫's fiddle and modified it:
https://jsfiddle.net/TwoFistedJustice/c3qr29L7/1/
Here is another fiddle based on this post:
https://jsfiddle.net/TwoFistedJustice/yu8Lzjvx/4/
I'm very perplexed.
Could someone please help me to:
Understand what is going on behind the scenes to make it behave it
this way.
Understand how to set a variable in an outer scope from inside
getCurrentPosition().
I've been reading up on the call stack and callback queue. And I gather that the behavior that has been perplexing me has to do with how Javascript handles the various stacks and queues. This piece by Jake Archibald helps to clear it up, though it is bit much to absorb all at once.
If I add a setTimeout with any delay value, even 0, foo is USUALLY changed. With near-zero values, it varies a bit.
setTimeout(function(){
console.log('SetTimeout\n - Foo only changes if this goes AFTER the Promise\n foo:', foo)}
, 0);
This is a fiddle derived from the others that more clearly shows what is going on. https://jsfiddle.net/TwoFistedJustice/arkqb0x8/71/

FastCode: studying its code

I'm studying the code of FastMM that change the address of the methods and function in run time. But I didn't understand some things.
http://koders.com/delphi/fid356C72C9C454FA74A916971690F624B0FF9111E5.aspx?s=pos
My doubt is on line 47: "if PBYTE(AStub)^ = $E8 then"
Why this comparison? Ok, to check if it's assigned or not. Am I wrong ? But why $E8(232) ?
If it's always the same value, wont it be always the same result ?
The rest of the code it's "ok" in my mind. But if some one could explain all of it I thank.
tks in advice.
That code returns the target address of a CALL instruction. The test is just to check that it really is a CALL instruction that has been passed to the routine. It's not fool proof because you could be passing the address of the middle of an instruction, or even something that isn't code.
So yes, the test should always succeed, if the function is called correctly.
These two routines are presumably used in tandem. First of all you get the address of the CALL instruction, and then the code at that site is replaced with a JMP ($E9).

BDE says "Field not found" but field exists

I have the following query to one of my database tables:
select count(*) as mycount
from mytable
where fieldone = :fieldone
and fieldtwo = :fieldtwo
Parameters are correctly loaded into the query (both of type String).
When I run this query outside the app (for instance, through the dbexplore) and replace the parameters with the actual values, I get the correct result. But when running it in the app, I get a Field 'fieldtwo' not found error, right on the Query.Open call.
Why would the BDE not find this field, when it actually exist?
Update: The following query, executed right after the first one (the one that fails), works fine in the app:
select *
from mytable
where fieldone = :fieldone
order by fieldone, fieldtwo
The best guess is that you have populated the field list in the query, this overrides any concept of the underlying fields that are in the query and is a cause of countless confusion.
Right click on the query, pick the fields editor clear all the values that are there and then choose 'add all fields' that should cause the missing field to appear once the query is executed.
I think it should auto-populate the fields if there are no defined fields when the query is executed, so you may not need to choose 'add all fields' after clearing the fields.
Whenever we come across a problem like this we tend to remove the query from the form and create it dynamically at run time... It depends how ingrained into the form it is...
E.g. If you have a data aware control looking at "fieldtwo" which tries to fetch some data when the underlying data set gets updated then it'll trigger an error like this, but it's more obvious when you've written code such
SomeEdit.Text = Query.FieldByName("fieldtwo").AsString;
That way it falls over on the relevant line instead of the open (triggering a related event)
Clear the query content using Query1.SQL.Clear; statement before opening it.
Other reason can be you are opening other database which may not have the specified field. Be sure that both the DatabaseName's in your app and dbexplore are same
I used to face porblems with BDE when i have SQLExplorer open and the app accesses the DB at the same time (but i had errors like ), try closing the Explorer it may help, if not i would build the SQL as text without the Parameters and try if it works then (if its possible in your situation).
I don't use parameters, so I'm just grabbing at straws here. I still use the BDE regularly, but am no expert. I find I shy away from more complex expressions (which yours is not!) because of the little "surprises" like this that the BDE throws at you.
Perhaps adding parentheses:
where (fieldone = :fieldone)
and (fieldtwo = :fieldtwo)
Or, single or double quote signs (this probably will make it worse?)
where (fieldon = ":fieldone")
and (fieldtwo = ":fieldtwo")
Or, to explore the problem, remove the "and fieldtwo = :fieldtwo" line and see if it runs.
Would it be possible for you to do your own parameter substitution with a StringReplace as in
Query1.SQL.Text := StringReplace(Query1.SQL.Text, ":fieldone", "MyVarName",[rfReplaceAll ]);
If you are creating a ClienDataSet in memory by the Create DataSet method, you should check the TFieldDefs property, which must have a different field name or not created
I was having a weird but small problem, I'll post in case it will help someone in some day.
uRegPeople.pas
with frmEditPerson do
begin
PersonID := qryPerson.FieldByName(ID).AsInteger;
...
end;
I had qryPerson both in frmRegPeople and in frmEditPerson, by using with I was referencing to frmEditPerson.qryPerson, however I wanted to reference to frmRegPeople.qryPerson. Then I need to change to the following code.
with frmEditPerson do
begin
PersonID := Self.qryPerson.FieldByName(ID).AsInteger;
...
end;
// Explanation
// qryPerson --> frmEditPerson.qryPerson;
// Self.qryPerson --> frmRegPeople.qryPerson;

insert to a different table onNewRecord

got an ADOQuery that has OnNewRecord event.
on the procedure i try to add data automaticaly to another table. the data is a few rows that are needed and handled in clientDataSet in case of cancellation.
at the loc
OtherAdoQuery.insert;
I get error that ADOQuery failed to insert null into a non null field. I am in insert mode, however I NEVER ASKED DELPHI TO POST! i dont find why it posts.
Edit: could you help me find a hint on this problem?
some more clarification:
at
ADOQuery.onNewRecord();
begin
CliendDataSet.insert; //here goes to post for ADOQueryPost. where ClientDataSet was in Browse State
end;
Edit:
this bug does not make sense! look at the stack trace:
beforePost
newRecord
myFunc
where myFunc does cause NewRecord with the Insert.
I'm not too familiar with TAdoQuery, but I know how to track down an error like this. First, if you don't already have it set, go into Project Options and turn on Use Debug DCUs under the Compile tab, then run a full build and run it. When you get that exception report in the debugger, hit Break and you should end up inside the code for the TAdoQuery or one of its sub-objects. Try examining the call stack. If you look up a few calls you'll probably find something that you did is calling something else that's calling Post. Follow the stack trace back until you reach your code and you'll get an idea of what's going on, and if you analyze it a little you should find some way to prevent the problem.
Having said that, let me make a quick guess as to the cause of your problem: When you call Insert on a dataset, if the dataset is already in appending mode because you previously called Insert or Append and didn't follow up with a Post, it will call Post itself before setting up a new row for you to work on. Maybe this is what's happening to you?
the answer was from a connection between the tables.
the ADOQuery.dataSource was set the DataSet of the ClientDataSet.
this mad so much damage, and no hint by the delphi.

Resources