Skip to content

Commit

Permalink
arithmetic operands should be null safe #163
Browse files Browse the repository at this point in the history
  • Loading branch information
abstratt committed Oct 1, 2019
1 parent e01831e commit d118198
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
34 changes: 17 additions & 17 deletions plugins/com.abstratt.mdd.core/models/libraries/mdd_types.tuml
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,37 @@ end;

class Boolean specializes Primitive
query \not() : Boolean;
query \and(b : Boolean[1]) : Boolean;
query \or(b : Boolean[1]) : Boolean;
query \xor(b : Boolean[1]) : Boolean;
query implies(b : Boolean[1]) : Boolean;
query \and(b : Boolean[0,1] := false) : Boolean;
query \or(b : Boolean[0,1] := false) : Boolean;
query \xor(b : Boolean[0,1] := false) : Boolean;
query implies(b : Boolean[0,1] := false) : Boolean;
end;

class Number specializes Primitive
query add(r : Number[1]) : Number;
query subtract(r : Number[1]) : Number;
query add(r : Number[0,1] := 0) : Number;
query subtract(r : Number[0,1] := 0) : Number;
query subtract() : Number;
query multiply(r : Number[1]) : Number;
query divide(r : Number[1]) : Number;
query multiply(r : Number[0,1] := 1) : Number;
query divide(r : Number[0,1] := 1) : Number;
query asInteger() : Integer;
query asDouble() : Double;
end;

class Integer specializes Double
query add(r : Integer[1]) : Integer;
query subtract(r : Integer[1]) : Integer;
query add(r : Integer[0,1] := 0) : Integer;
query subtract(r : Integer[0,1] := 0) : Integer;
query subtract() : Integer;
query multiply(r : Integer[1]) : Integer;
query divide(r : Integer[1]) : Integer;
query modulo(r : Integer[1]) : Integer;
query multiply(r : Integer[0,1] := 1) : Integer;
query divide(r : Integer[0,1] := 1) : Integer;
query modulo(r : Integer[0,1] := 0) : Integer;
query absolute() : Integer;
end;

class Double specializes Number
query add(r : Number[1]) : Double;
query subtract(r : Number[1]) : Double;
query multiply(r : Number[1]) : Double;
query divide(r : Number[1]) : Double;
query add(r : Number[0,1] := 0) : Double;
query subtract(r : Number[0,1] := 0) : Double;
query multiply(r : Number[0,1] := 1) : Double;
query divide(r : Number[0,1] := 1) : Double;
query subtract() : Double;
query fractionalPart() : Double;
query absolute() : Double;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.abstratt.mdd.core.IRepository;
import com.abstratt.mdd.core.Step;
import com.abstratt.mdd.core.util.TypeUtils;
import com.abstratt.mdd.frontend.core.TypeMismatch;
import com.abstratt.mdd.frontend.core.UnknownType;
import com.abstratt.mdd.frontend.core.spi.AbortedScopeCompilationException;
Expand All @@ -33,11 +34,13 @@ public class SimpleInitializationExpressionProcessor {
private IReferenceTracker referenceTracker;
private ProblemBuilder<Node> problemBuilder;
private Namespace currentNamespace;
private IRepository repository;

SimpleInitializationExpressionProcessor(SourceCompilationContext<Node> sourceContext, Namespace currentNamespace) {
this.referenceTracker = sourceContext.getReferenceTracker();
this.problemBuilder = sourceContext.getProblemBuilder();
this.currentNamespace = currentNamespace;
this.repository = sourceContext.getContext().getRepository();
}

protected ValueSpecification parseValueSpecification(PLiteralOrIdentifier node, final Type expectedType) {
Expand Down Expand Up @@ -85,7 +88,7 @@ protected void onBind(Type element) {
final ValueSpecification valueSpec = parseValueSpecification(initializationExpression,
typedElement.getType());
if (valueSpec != null) {
if (typedElement.getType() != valueSpec.getType())
if (!TypeUtils.isCompatible(repository, valueSpec, typedElement, null))
problemBuilder.addProblem(new TypeMismatch(typedElement.getType().getQualifiedName(), valueSpec
.getType().getQualifiedName()), typeIdentifierNode);
else {
Expand Down

0 comments on commit d118198

Please sign in to comment.