Typesystem Comparison Rule not working
Hi Folks,
i m just improving our mps based DB mapper in order to allow for some java Expression like
Invoices.where( invoice.id == null )
The == is a baselang EqualsExpression, leading to a Typesystem error. Since id is of type int, one can not compare it to null. In order to circumvent this behaviour, i set up a Typesystem Comparison-Rule in my DB mapper language.

But that rule not even gets call.... Obviously, i m forgetting something important here... How can i fix the baselang typesystem to allow something like
if (10 == null) {
}
- just in the editor of course, not in the gen code ....
Any hints appreciated,
Dan
Please sign in to leave a comment.
The way comparison rules work, only those rules are consulted, that are defined by language(s) that the types in question belong to. You can't modify the behaviour of the types that belong to BaseLanguage by adding arbitrary rules in an extension language. And that is probably a good thing.
What you could do, however, is to define your own type, let's say "NullableIntegerType" and create corresponding comparison rule for it.
HTH.
Hi Fedor,
thanks for your comment. Totally understand the NullableIntegerType. But how can i get NullableIntegerType a subtype of IntegerType within my "Nullable Context Concept" (a specific Concept extending BaseMethodDeclaration, where the nullable is allowed).
Is there no way to use Inequation Replacement Rule to allow some expressions like
myNullableContextMethod (int a) {
GENERATE SQL CODE FOR EXPRESSION: (a == null)
}
HFAI
Dan
Why not declare your method to accept a parameter of NullableIntegerType? Then you can make IntegerType a subtype of that type, in this way you keep compatibility with BL's type system.
Mh,
yes indeed. I could imaging bringing in a cast operator (nullable a) == 10 for expressions..
okay, but from your point of view, there is no possibility to get rid of the baselang error message
"type int is not comparable with nulltype"
Cheers for your help Fedor! Great!
Dan