Unknown error on VDM++ toolbox lite - vdm++

I'm doing VDM++ on VDM++ toolbox lite and below is my example code:
class Course
types
public study :: numsubj : nat1
sem : nat1;
public subjpersem = nat1;
operations
public getsubj:nat1 * nat1 ==>study
getsubj(numsubj,sem) == (
subjpersem := numsubj/sem;
);
end Course
I tried to run the code. Succeeded creating the object but when I run print getsubj(10,2), it returns error Run-Time Error 120: Unknown state component
Can somebody help me thank you in advance

In Overture/VDMJ, this spec gives two type checking errors. Do these not appear in VDMTools?
Error 3247: Symbol 'subjpersem' is not an updatable variable in 'Course' (test.vpp) at line 9:5
Error 3027: Operation returns unexpected type in 'Course' (test.vpp) at line 7:8
Actual: ()
Expected: study
Type checked 1 class in 0.119 secs. Found 2 type errors

Related

Drools - how do I compare a string value present in a Java Object which is present inside a List

I am new to Drools and am having a tough time writing rules
Here is my data structure :
public class Premium{
private List<InsuranceType> insuranceTypes;
}
public class InsuranceType {
private String name;
}
So a Premium object will contain a List of Insurance types and I need to check if any of the insurance types has a name of "TPD"
Have tried the following :
rule "rule#3"
when
$fact:Premium($insuranceTypes : InsuranceType(name == 'TPD'))
then
System.out.println("Error");
end
However app server fails to start with the following error:
2021-11-30 12:16:37.004 ERROR 23500 --- [ main]
o.d.c.k.builder.impl.AbstractKieModule : Unable to build KieBaseModel:defaultKieBase
Unable to Analyse Expression InsuranceType(name == "TPD"):
[Error: unable to resolve method using strict-mode: com.xyz.Premium.name()]
[Near : {... InsuranceType(name == "TPD") ....}]
^
[Line: 29, Column: 5] : [Rule name='rule#3']
Unable to analyze expression 'InsuranceType(name == "TPD")' : [Rule name='rule#3']
Field Reader does not exist for declaration '$insuranceTypes' in '$insuranceTypes :
InsuranceType(name == "TPD")' in the rule 'rule#3' : [Rule name='rule#3']
I'm going to assume there's a public getName method on the InsuranceType class, and a public getInsuranceTypes method on the Premium class. If either of those isn't true, you need to add either getters or make those properties public.
Your rule was pretty close. However the problem you have is that insuranceTypes is a list but you were treating it as an object.
You have several options here, depending on your needs. However I'd go with the simplest, which is this:
rule "Example"
when
Premium( $insuranceTypes: insuranceTypes )
exists( InsuranceType( name == "TPD" ) from $insuranceTypes )
then
System.out.println("Error");
end
In the first line, I get the insurance types and assign them to the variable $insuranceTypes. This variable is now the list of types.
Then in the second line, I assert that there exists at least one InsuranceType in the list that has the name "TPD".
Note that Drools also has a memberOf operator, and a contains operator, which come in useful when working with lists and other iterable collections. These are inverses of each other, eg. you'd do Example( foo memberOf $someList ) or Example( myList contains $something ).

Drools Error : Unable to find #positional field

I created a drool file PersonTotalAccountsBalance.drl as below. I am beginner in the rules engine world.
package com.auhuman.rules;
import com.auhuman.Person;
import com.auhuman.Account;
function float getTotalBalance(Person person) {
float totalBalance = 0;
for (Account account : person.getAccounts()){
totalBalance += account.getBalance();
}
return totalBalance;
}
rule "PersonTotalAccountsBalance"
when
$node : Person(active == true)
then
float totalBalance = getTotalBalance($node)
modify($node) {
setTotalBalance(totalBalance);
}
end
Upon compile I am getting below error
Unable to compile the file: PersonTotalAccountsBalance.drl. Errors = [Unable to find #positional field 0 for class Person
: [Rule name='PersonTotalAccountsBalance']
]
Although this question is very old:
I had the same error message but I was working with decision tables in xls (excel) format. The table looked like this:
Note that $order:Order is in a merged cell goes across both the CONDITION and the ACTION columns. That cell is only allowed to be above CONDITION tables, not the ACTION tables. After unmerging I didn't get the error anymore:
I got a very similar error when defining the wrong values in the ACTION column for setting an attribute. When using values without quotes for a String attribute in the model Order I got the following error:
Unable to get KieModule, Errors Existed: Error Messages:
Message [id=1, kieBase=defaultKieBase, level=ERROR, path=status_rules/status.xls, line=21, column=0
text=Rule Compilation error The method setNextStatus(String) in the type Order is not applicable for the arguments (int)]
Message [id=2, kieBase=defaultKieBase, level=ERROR, path=status_rules/status.xls, line=5, column=0
text=Rule Compilation error The method setNextStatus(String) in the type Order is not applicable for the arguments (int)]
Message [id=3, kieBase=defaultKieBase, level=ERROR, path=status_rules/status.xls, line=13, column=0
text=Rule Compilation error The method setNextStatus(String) in the type Order is not applicable for the arguments (int)]
However in this case the error message was more precise.

orientdb db.save "object is ambiguous" error

I'm using release orientdb-community-2.1.9.
Following example in docs (http://orientdb.com/docs/2.1/Functions.html)
I tried:
return db.save({
"#class": "V",
log: 'test'
});
And I've got this error:
Error on parsing script at position #0: Error on execution of the script\nScript: test\n------^\nsun.org.mozilla.javascript.EvaluatorException: The choice of Java method com.orientechnologies.orient.core.command.script.OScriptDocumentDatabaseWrapper.save matching JavaScript argument types (object) is ambiguous; candidate methods are: \n class com.orientechnologies.orient.core.record.impl.ODocument save(com.orientechnologies.orient.core.record.ORecord)\n class com.orientechnologies.orient.core.record.impl.ODocument save(java.util.Map) (#360) in at line number 360\nThe choice of Java method com.orientechnologies.orient.core.command.script.OScriptDocumentDatabaseWrapper.save matching JavaScript argument types (object) is ambiguous; candidate methods are: \n class com.orientechnologies.orient.core.record.impl.ODocument save(com.orientechnologies.orient.core.record.ORecord)\n class com.orientechnologies.orient.core.record.impl.ODocument save(java.util.Map) (#360)
How can I correct this ambiguity?
Thanks
Luca

initialize systemverilog (ovm) parameterized class array

I want to monitor several analysis ports, and "publish" the item through one analysis port.
It works for predefined item type, but fail to be parameterized.
The code:
class ovm_analysis_sink #(int NUM_PORTS = 1, type T = ovm_object ) extends ovm_component;
// .......................................
`ovm_component_param_utils(ovm_analysis_sink#(NUM_PORTS,T))
// .......................................
ovm_analysis_imp #(T,ovm_analysis_sink) mon_analysis_imp[NUM_PORTS-1:0];
ovm_analysis_port #(T) mon_analysis_port = new("mon_analysis_port", this);
virtual function void build() ;
string inst;
for(int i=0 ;i < NUM_PORTS ;i++ )
begin
$sformat(inst,"mon_analysis_imp_%0d",i);
mon_analysis_imp[i] = new(inst,this);
end
super.build() ;
endfunction : build
The usage of the analysis_sink:
ovm_analysis_sink #(3,a_type) a_item_sink;
And the error message:
Error-[ICTTFC] Incompatible complex type usage ovm_tb.sv, 42
Incompatible complex type usage in task or function call.
The following expression is incompatible with the formal parameter of the function.
The type of the actual is 'class $unit::ovm_analysis_sink#(3,class $unit::a_type)',
while the type of the formal is 'class $unit::ovm_analysis_sink#(1,class ovm_pkg::ovm_object)'.
Expression: this Source info: ovm_analysis_imp::new(inst, this)
The error says type incompatibility. That means the actual (run-time) and formal (compile-time) arguments/types of implementation port is not the same.
There is an error while declaration of analysis port. Declaring the port as shown above creates a handle of analysis imp port of type uvm_analysis_sink #(1,uvm_object) while, you want it to be of type uvm_analysis_sink #(3,a_type).
So, declare it as follows:
ovm_analysis_imp #(T,ovm_analysis_sink#(NUM_PORTS,T)) mon_analysis_imp[NUM_PORTS-1:0];
This shall remove the type conflict and make it type assignment compatible. Now any parameter overriding shall work.
I have created a sample UVM code on EDAPlayground for reference. Similar applies to your OVM testbench. For further information refer to this forum question.

private type declaration is throwing error?

private type declaration is throwing error?my code is below please help me to fix it
error is=> "missing full declaration of private type t"
spec file
package rec is
type t is private;
give_public_acess:Constant t;
private
type int_array is array(1..5)of integer;
type t_type is record
max:integer:=0;
data:int_array;
end record;
give_public_acess:constant t_type:=(0,(others=>1)); --error is here adacore site says these is good but throwing error?
end rec;
When I compile your code I get 2 error messages:
rec.ads:2:07: missing full declaration for private type "t"
rec.ads:10:03: type does not match declaration at line 3
These are both because you call the type t in the public part and t_type in the private part. The first means exactly what it says; the second is because in the public part you say
give_public_acess:Constant t;
and in the private part
give_public_acess:constant t_type
I suggest you try compiling with -gnatl (full listing): this intersperses error messages with the code, so you get
1. package rec is
2. type t is private;
|
>>> missing full declaration for private type "t"
3. give_public_acess:Constant t;
4. private
5. type int_array is array(1..5)of integer;
6. type t_type is record
7. max:integer:=0;
8. data:int_array;
9. end record;
10. give_public_acess:constant t_type:=(0,(others=>1)); --error is here adacore site says these is good but throwing error?
|
>>> type does not match declaration at line 3
11. end rec;