forbid non-generic comparison in 1.dev (#5020)

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Remy 2020-03-16 18:25:43 +01:00 committed by GitHub
parent 04a0723c81
commit 04196597a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 191 additions and 27 deletions

View File

@ -1404,7 +1404,12 @@ private[lf] object DecodeV1 {
BuiltinFunctionInfo(GENMAP_SIZE, BGenMapSize, minVersion = genMap), BuiltinFunctionInfo(GENMAP_SIZE, BGenMapSize, minVersion = genMap),
BuiltinFunctionInfo(APPEND_TEXT, BAppendText), BuiltinFunctionInfo(APPEND_TEXT, BAppendText),
BuiltinFunctionInfo(ERROR, BError), BuiltinFunctionInfo(ERROR, BError),
BuiltinFunctionInfo(LEQ_INT64, BLessEq, implicitParameters = List(TInt64)), BuiltinFunctionInfo(
LEQ_INT64,
BLessEq,
implicitParameters = List(TInt64),
maxVersion = Some(genComparison),
),
BuiltinFunctionInfo( BuiltinFunctionInfo(
LEQ_DECIMAL, LEQ_DECIMAL,
BLessEq, BLessEq,
@ -1414,16 +1419,30 @@ private[lf] object DecodeV1 {
BuiltinFunctionInfo( BuiltinFunctionInfo(
LEQ_NUMERIC, LEQ_NUMERIC,
BLessEqNumeric, BLessEqNumeric,
maxVersion = Some(genComparison),
minVersion = numeric, minVersion = numeric,
), ),
BuiltinFunctionInfo(LEQ_TEXT, BLessEq, implicitParameters = List(TText)), BuiltinFunctionInfo(
BuiltinFunctionInfo(LEQ_TIMESTAMP, BLessEq, implicitParameters = List(TTimestamp)), LEQ_TEXT,
BLessEq,
maxVersion = Some(genComparison),
implicitParameters = List(TText)),
BuiltinFunctionInfo(
LEQ_TIMESTAMP,
BLessEq,
maxVersion = Some(genComparison),
implicitParameters = List(TTimestamp)),
BuiltinFunctionInfo( BuiltinFunctionInfo(
LEQ_PARTY, LEQ_PARTY,
BLessEq, BLessEq,
implicitParameters = List(TParty), minVersion = partyOrdering,
minVersion = partyOrdering), maxVersion = Some(genComparison),
BuiltinFunctionInfo(GEQ_INT64, BGreaterEq, implicitParameters = List(TInt64)), implicitParameters = List(TParty)),
BuiltinFunctionInfo(
GEQ_INT64,
BGreaterEq,
maxVersion = Some(genComparison),
implicitParameters = List(TInt64)),
BuiltinFunctionInfo( BuiltinFunctionInfo(
GEQ_DECIMAL, GEQ_DECIMAL,
BGreaterEq, BGreaterEq,
@ -1434,15 +1453,30 @@ private[lf] object DecodeV1 {
GEQ_NUMERIC, GEQ_NUMERIC,
BGreaterEqNumeric, BGreaterEqNumeric,
minVersion = numeric, minVersion = numeric,
maxVersion = Some(genComparison),
), ),
BuiltinFunctionInfo(GEQ_TEXT, BGreaterEq, implicitParameters = List(TText)), BuiltinFunctionInfo(
BuiltinFunctionInfo(GEQ_TIMESTAMP, BGreaterEq, implicitParameters = List(TTimestamp)), GEQ_TEXT,
BGreaterEq,
maxVersion = Some(genComparison),
implicitParameters = List(TText)),
BuiltinFunctionInfo(
GEQ_TIMESTAMP,
BGreaterEq,
maxVersion = Some(genComparison),
implicitParameters = List(TTimestamp)),
BuiltinFunctionInfo( BuiltinFunctionInfo(
GEQ_PARTY, GEQ_PARTY,
BGreaterEq, BGreaterEq,
minVersion = partyOrdering,
maxVersion = Some(genComparison),
implicitParameters = List(TParty), implicitParameters = List(TParty),
minVersion = partyOrdering), ),
BuiltinFunctionInfo(LESS_INT64, BLess, implicitParameters = List(TInt64)), BuiltinFunctionInfo(
LESS_INT64,
BLess,
maxVersion = Some(genComparison),
implicitParameters = List(TInt64)),
BuiltinFunctionInfo( BuiltinFunctionInfo(
LESS_DECIMAL, LESS_DECIMAL,
BLess, BLess,
@ -1453,15 +1487,30 @@ private[lf] object DecodeV1 {
LESS_NUMERIC, LESS_NUMERIC,
BLessNumeric, BLessNumeric,
minVersion = numeric, minVersion = numeric,
maxVersion = Some(genComparison),
), ),
BuiltinFunctionInfo(LESS_TEXT, BLess, implicitParameters = List(TText)), BuiltinFunctionInfo(
BuiltinFunctionInfo(LESS_TIMESTAMP, BLess, implicitParameters = List(TTimestamp)), LESS_TEXT,
BLess,
maxVersion = Some(genComparison),
implicitParameters = List(TText)),
BuiltinFunctionInfo(
LESS_TIMESTAMP,
BLess,
maxVersion = Some(genComparison),
implicitParameters = List(TTimestamp)),
BuiltinFunctionInfo( BuiltinFunctionInfo(
LESS_PARTY, LESS_PARTY,
BLess, BLess,
implicitParameters = List(TParty), minVersion = partyOrdering,
minVersion = partyOrdering), maxVersion = Some(genComparison),
BuiltinFunctionInfo(GREATER_INT64, BGreater, implicitParameters = List(TInt64)), implicitParameters = List(TParty)
),
BuiltinFunctionInfo(
GREATER_INT64,
BGreater,
maxVersion = Some(genComparison),
implicitParameters = List(TInt64)),
BuiltinFunctionInfo( BuiltinFunctionInfo(
GREATER_DECIMAL, GREATER_DECIMAL,
BGreater, BGreater,
@ -1472,14 +1521,25 @@ private[lf] object DecodeV1 {
GREATER_NUMERIC, GREATER_NUMERIC,
BGreaterNumeric, BGreaterNumeric,
minVersion = numeric, minVersion = numeric,
maxVersion = Some(genComparison),
), ),
BuiltinFunctionInfo(GREATER_TEXT, BGreater, implicitParameters = List(TText)), BuiltinFunctionInfo(
BuiltinFunctionInfo(GREATER_TIMESTAMP, BGreater, implicitParameters = List(TTimestamp)), GREATER_TEXT,
BGreater,
maxVersion = Some(genComparison),
implicitParameters = List(TText)),
BuiltinFunctionInfo(
GREATER_TIMESTAMP,
BGreater,
maxVersion = Some(genComparison),
implicitParameters = List(TTimestamp)),
BuiltinFunctionInfo( BuiltinFunctionInfo(
GREATER_PARTY, GREATER_PARTY,
BGreater, BGreater,
minVersion = partyOrdering,
maxVersion = Some(genComparison),
implicitParameters = List(TParty), implicitParameters = List(TParty),
minVersion = partyOrdering), ),
BuiltinFunctionInfo(TO_TEXT_INT64, BToTextInt64), BuiltinFunctionInfo(TO_TEXT_INT64, BToTextInt64),
BuiltinFunctionInfo( BuiltinFunctionInfo(
TO_TEXT_DECIMAL, TO_TEXT_DECIMAL,

View File

@ -83,6 +83,16 @@ class DecodeV1Spec
LV.Minor.Dev LV.Minor.Dev
) )
private val preGenericComparisonVersion = Table(
"minVersion",
List(1, 4, 6, 8).map(i => LV.Minor.Stable(i.toString)): _*
)
private val postGenericComparisonVersion = Table(
"minVersion",
LV.Minor.Dev
)
private val preAnyTypeVersions = Table( private val preAnyTypeVersions = Table(
"minVersion", "minVersion",
List("1", "4", "6").map(LV.Minor.Stable): _* List("1", "4", "6").map(LV.Minor.Stable): _*
@ -118,7 +128,6 @@ class DecodeV1Spec
"accept nat kind if lf version >= 1.7" in { "accept nat kind if lf version >= 1.7" in {
val input = DamlLf1.Kind.newBuilder().setNat(DamlLf1.Unit.newBuilder()).build() val input = DamlLf1.Kind.newBuilder().setNat(DamlLf1.Unit.newBuilder()).build()
forEvery(postNumericMinVersions) { minVersion => forEvery(postNumericMinVersions) { minVersion =>
moduleDecoder(minVersion).decodeKind(input) shouldBe Ast.KNat moduleDecoder(minVersion).decodeKind(input) shouldBe Ast.KNat
} }
@ -321,15 +330,58 @@ class DecodeV1Spec
DamlLf1.BuiltinFunction.MUL_NUMERIC -> Ast.EBuiltin(Ast.BMulNumeric), DamlLf1.BuiltinFunction.MUL_NUMERIC -> Ast.EBuiltin(Ast.BMulNumeric),
DamlLf1.BuiltinFunction.DIV_NUMERIC -> Ast.EBuiltin(Ast.BDivNumeric), DamlLf1.BuiltinFunction.DIV_NUMERIC -> Ast.EBuiltin(Ast.BDivNumeric),
DamlLf1.BuiltinFunction.ROUND_NUMERIC -> Ast.EBuiltin(Ast.BRoundNumeric), DamlLf1.BuiltinFunction.ROUND_NUMERIC -> Ast.EBuiltin(Ast.BRoundNumeric),
DamlLf1.BuiltinFunction.LEQ_NUMERIC -> Ast.EBuiltin(Ast.BLessEqNumeric),
DamlLf1.BuiltinFunction.LESS_NUMERIC -> Ast.EBuiltin(Ast.BLessNumeric),
DamlLf1.BuiltinFunction.GEQ_NUMERIC -> Ast.EBuiltin(Ast.BGreaterEqNumeric),
DamlLf1.BuiltinFunction.GREATER_NUMERIC -> Ast.EBuiltin(Ast.BGreaterNumeric),
DamlLf1.BuiltinFunction.TO_TEXT_NUMERIC -> Ast.EBuiltin(Ast.BToTextNumeric), DamlLf1.BuiltinFunction.TO_TEXT_NUMERIC -> Ast.EBuiltin(Ast.BToTextNumeric),
DamlLf1.BuiltinFunction.FROM_TEXT_NUMERIC -> Ast.EBuiltin(Ast.BFromTextNumeric), DamlLf1.BuiltinFunction.FROM_TEXT_NUMERIC -> Ast.EBuiltin(Ast.BFromTextNumeric),
DamlLf1.BuiltinFunction.INT64_TO_NUMERIC -> Ast.EBuiltin(Ast.BInt64ToNumeric), DamlLf1.BuiltinFunction.INT64_TO_NUMERIC -> Ast.EBuiltin(Ast.BInt64ToNumeric),
DamlLf1.BuiltinFunction.NUMERIC_TO_INT64 -> Ast.EBuiltin(Ast.BNumericToInt64), DamlLf1.BuiltinFunction.NUMERIC_TO_INT64 -> Ast.EBuiltin(Ast.BNumericToInt64),
)
val comparisonBuiltinCases = Table(
"compare builtins" -> "expected output",
DamlLf1.BuiltinFunction.EQUAL_INT64 -> Ast.ETyApp(Ast.EBuiltin(Ast.BEqual), TInt64),
DamlLf1.BuiltinFunction.LEQ_INT64 -> Ast.ETyApp(Ast.EBuiltin(Ast.BLessEq), TInt64),
DamlLf1.BuiltinFunction.LESS_INT64 -> Ast.ETyApp(Ast.EBuiltin(Ast.BLess), TInt64),
DamlLf1.BuiltinFunction.GEQ_INT64 -> Ast.ETyApp(Ast.EBuiltin(Ast.BGreaterEq), TInt64),
DamlLf1.BuiltinFunction.GREATER_INT64 -> Ast.ETyApp(Ast.EBuiltin(Ast.BGreater), TInt64),
DamlLf1.BuiltinFunction.EQUAL_DATE -> Ast.ETyApp(Ast.EBuiltin(Ast.BEqual), TDate),
DamlLf1.BuiltinFunction.LEQ_DATE -> Ast.ETyApp(Ast.EBuiltin(Ast.BLessEq), TDate),
DamlLf1.BuiltinFunction.LESS_DATE -> Ast.ETyApp(Ast.EBuiltin(Ast.BLess), TDate),
DamlLf1.BuiltinFunction.GEQ_DATE -> Ast.ETyApp(Ast.EBuiltin(Ast.BGreaterEq), TDate),
DamlLf1.BuiltinFunction.GREATER_DATE -> Ast.ETyApp(Ast.EBuiltin(Ast.BGreater), TDate),
DamlLf1.BuiltinFunction.EQUAL_TIMESTAMP -> Ast.ETyApp(Ast.EBuiltin(Ast.BEqual), TTimestamp),
DamlLf1.BuiltinFunction.LEQ_TIMESTAMP -> Ast.ETyApp(Ast.EBuiltin(Ast.BLessEq), TTimestamp),
DamlLf1.BuiltinFunction.LESS_TIMESTAMP -> Ast.ETyApp(Ast.EBuiltin(Ast.BLess), TTimestamp),
DamlLf1.BuiltinFunction.GEQ_TIMESTAMP -> Ast.ETyApp(Ast.EBuiltin(Ast.BGreaterEq), TTimestamp),
DamlLf1.BuiltinFunction.GREATER_TIMESTAMP -> Ast
.ETyApp(Ast.EBuiltin(Ast.BGreater), TTimestamp),
DamlLf1.BuiltinFunction.EQUAL_TEXT -> Ast.ETyApp(Ast.EBuiltin(Ast.BEqual), TText),
DamlLf1.BuiltinFunction.LEQ_TEXT -> Ast.ETyApp(Ast.EBuiltin(Ast.BLessEq), TText),
DamlLf1.BuiltinFunction.LESS_TEXT -> Ast.ETyApp(Ast.EBuiltin(Ast.BLess), TText),
DamlLf1.BuiltinFunction.GEQ_TEXT -> Ast.ETyApp(Ast.EBuiltin(Ast.BGreaterEq), TText),
DamlLf1.BuiltinFunction.GREATER_TEXT -> Ast.ETyApp(Ast.EBuiltin(Ast.BGreater), TText),
DamlLf1.BuiltinFunction.EQUAL_PARTY -> Ast.ETyApp(Ast.EBuiltin(Ast.BEqual), TParty),
DamlLf1.BuiltinFunction.LEQ_PARTY -> Ast.ETyApp(Ast.EBuiltin(Ast.BLessEq), TParty),
DamlLf1.BuiltinFunction.LESS_PARTY -> Ast.ETyApp(Ast.EBuiltin(Ast.BLess), TParty),
DamlLf1.BuiltinFunction.GEQ_PARTY -> Ast.ETyApp(Ast.EBuiltin(Ast.BGreaterEq), TParty),
DamlLf1.BuiltinFunction.GREATER_PARTY -> Ast.ETyApp(Ast.EBuiltin(Ast.BGreater), TParty),
)
val numericComparisonBuiltinCases = Table(
"numeric comparison builtins" -> "expected output",
DamlLf1.BuiltinFunction.EQUAL_NUMERIC -> Ast.EBuiltin(Ast.BEqualNumeric), DamlLf1.BuiltinFunction.EQUAL_NUMERIC -> Ast.EBuiltin(Ast.BEqualNumeric),
DamlLf1.BuiltinFunction.LEQ_NUMERIC -> Ast.EBuiltin(Ast.BLessEqNumeric),
DamlLf1.BuiltinFunction.LESS_NUMERIC -> Ast.EBuiltin(Ast.BLessNumeric),
DamlLf1.BuiltinFunction.GEQ_NUMERIC -> Ast.EBuiltin(Ast.BGreaterEqNumeric),
DamlLf1.BuiltinFunction.GREATER_NUMERIC -> Ast.EBuiltin(Ast.BGreaterNumeric),
)
val genericComparisonBuiltinCases = Table(
"generic comparison builtins" -> "expected output",
DamlLf1.BuiltinFunction.EQUAL -> Ast.EBuiltin(Ast.BEqual),
DamlLf1.BuiltinFunction.LESS_EQ -> Ast.EBuiltin(Ast.BLessEq),
DamlLf1.BuiltinFunction.LESS -> Ast.EBuiltin(Ast.BLess),
DamlLf1.BuiltinFunction.GREATER_EQ -> Ast.EBuiltin(Ast.BGreaterEq),
DamlLf1.BuiltinFunction.GREATER -> Ast.EBuiltin(Ast.BGreater),
) )
val negativeBuiltinTestCases = Table( val negativeBuiltinTestCases = Table(
@ -375,14 +427,27 @@ class DecodeV1Spec
"translate Numeric builtins as is if version >= 1.7" in { "translate Numeric builtins as is if version >= 1.7" in {
val v1_7 = LV.Minor.Stable("7")
forEvery(postNumericMinVersions) { version => forEvery(postNumericMinVersions) { version =>
val decoder = moduleDecoder(version) val decoder = moduleDecoder(version)
forEvery(numericBuiltinTestCases) { (proto, scala) => forEvery(numericBuiltinTestCases) { (proto, scala) =>
if (proto != DamlLf1.BuiltinFunction.EQUAL_NUMERIC || version == v1_7) decoder.decodeExpr(toProtoExpr(proto), "test") shouldBe scala
decoder.decodeExpr(toProtoExpr(proto), "test") shouldBe scala }
}
}
"translate numeric comparison builtins as is if version >= 1.7" in {
val v1_7 = LV.Minor.Stable("7")
forEvery(postNumericMinVersions) { version =>
whenever(!postGenericComparisonVersion.contains(version)) {
val decoder = moduleDecoder(version)
forEvery(numericComparisonBuiltinCases) { (proto, scala) =>
if (proto != DamlLf1.BuiltinFunction.EQUAL_NUMERIC || version == v1_7)
decoder.decodeExpr(toProtoExpr(proto), "test") shouldBe scala
}
} }
} }
} }
@ -517,6 +582,45 @@ class DecodeV1Spec
} }
} }
"translate comparison builtins as is if version < 1.9" in {
forEvery(preGenericComparisonVersion) { version =>
val decoder = moduleDecoder(version)
forEvery(comparisonBuiltinCases) { (proto, scala) =>
decoder.decodeExpr(toProtoExpr(proto), "test") shouldBe scala
}
}
}
"reject comparison builtins as is if version >= 1.9" in {
forEvery(preGenericComparisonVersion) { version =>
val decoder = moduleDecoder(version)
forEvery(genericComparisonBuiltinCases) { (proto, _) =>
a[ParseError] shouldBe thrownBy(decoder.decodeExpr(toProtoExpr(proto), "test"))
}
}
}
"translate generic comparison builtins as is if version >= 1.9" in {
forEvery(postGenericComparisonVersion) { version =>
val decoder = moduleDecoder(version)
forEvery(genericComparisonBuiltinCases) { (proto, scala) =>
decoder.decodeExpr(toProtoExpr(proto), "test") shouldBe scala
}
}
}
"translate generic comparison builtins as is if version < 1.9" in {
forEvery(preGenericComparisonVersion) { version =>
val decoder = moduleDecoder(version)
forEvery(genericComparisonBuiltinCases) { (proto, scala) =>
a[ParseError] shouldBe thrownBy(decoder.decodeExpr(toProtoExpr(proto), "test"))
}
}
}
} }
"decodeModuleRef" should { "decodeModuleRef" should {