@@ -14,17 +14,18 @@ trait ValidateOps extends ExceptionNames {
1414 val typeProvider : ClassTypeProvider
1515
1616 def attrValidate (attrId : Identifier , attr : AttrLikeSpec , valid : ValidationSpec ): Unit = {
17+ val attrTypeRef = attr.dataType.asNonOwning()
1718 val itemValue = Identifier .itemExpr(attrId, attr.cond.repeat)
1819 valid match {
1920 case ValidationEq (expected) =>
20- attrValidateExprCompare(attrId, attr, Ast .cmpop.Eq , expected, ValidationNotEqualError (attr.dataType ))
21+ attrValidateExprCompare(attrId, attr, Ast .cmpop.Eq , expected, ValidationNotEqualError (attrTypeRef ))
2122 case ValidationMin (min) =>
22- attrValidateExprCompare(attrId, attr, Ast .cmpop.GtE , min, ValidationLessThanError (attr.dataType ))
23+ attrValidateExprCompare(attrId, attr, Ast .cmpop.GtE , min, ValidationLessThanError (attrTypeRef ))
2324 case ValidationMax (max) =>
24- attrValidateExprCompare(attrId, attr, Ast .cmpop.LtE , max, ValidationGreaterThanError (attr.dataType ))
25+ attrValidateExprCompare(attrId, attr, Ast .cmpop.LtE , max, ValidationGreaterThanError (attrTypeRef ))
2526 case ValidationRange (min, max) =>
26- attrValidateExprCompare(attrId, attr, Ast .cmpop.GtE , min, ValidationLessThanError (attr.dataType ))
27- attrValidateExprCompare(attrId, attr, Ast .cmpop.LtE , max, ValidationGreaterThanError (attr.dataType ))
27+ attrValidateExprCompare(attrId, attr, Ast .cmpop.GtE , min, ValidationLessThanError (attrTypeRef ))
28+ attrValidateExprCompare(attrId, attr, Ast .cmpop.LtE , max, ValidationGreaterThanError (attrTypeRef ))
2829 case ValidationAnyOf (values) =>
2930 val bigOrExpr = Ast .expr.BoolOp (
3031 Ast .boolop.Or ,
@@ -39,9 +40,9 @@ trait ValidateOps extends ExceptionNames {
3940
4041 attrValidateExpr(
4142 attrId,
42- attr.dataType ,
43+ attrTypeRef ,
4344 checkExpr = bigOrExpr,
44- err = ValidationNotAnyOfError (attr.dataType ),
45+ err = ValidationNotAnyOfError (attrTypeRef ),
4546 errArgs = List (
4647 itemValue,
4748 Ast .expr.InternalName (IoIdentifier ),
@@ -50,17 +51,20 @@ trait ValidateOps extends ExceptionNames {
5051 )
5152 case ValidationExpr (expr) =>
5253 blockScopeHeader
53- typeProvider._currentIteratorType = Some (attr.dataType)
54+ typeProvider._currentIteratorType = Some (attrTypeRef)
55+ // Store value of attribute in the temporary variable with a name that is
56+ // used for `_` variable, because in expression we refer to current value
57+ // using this variable
5458 handleAssignmentTempVar(
55- attr.dataType ,
59+ attrTypeRef ,
5660 translator.translate(Ast .expr.Name (Ast .identifier(Identifier .ITERATOR ))),
5761 translator.translate(itemValue)
5862 )
5963 attrValidateExpr(
6064 attrId,
61- attr.dataType ,
65+ attrTypeRef ,
6266 expr,
63- ValidationExprError (attr.dataType ),
67+ ValidationExprError (attrTypeRef ),
6468 List (
6569 itemValue,
6670 Ast .expr.InternalName (IoIdentifier ),
@@ -75,7 +79,7 @@ trait ValidateOps extends ExceptionNames {
7579 val itemValue = Identifier .itemExpr(attrId, attr.cond.repeat)
7680 attrValidateExpr(
7781 attrId,
78- attr.dataType,
82+ attr.dataType.asNonOwning() ,
7983 checkExpr = Ast .expr.Compare (
8084 itemValue,
8185 op,
0 commit comments