LF: Test scala interface type checking (#11833)

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Remy 2021-11-24 16:58:45 +01:00 committed by GitHub
parent 5f52f00afb
commit 86da6e8eef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 664 additions and 284 deletions

View File

@ -340,7 +340,7 @@ private[parser] class ExprParser[P](parserParameters: ParserParameters[P]) {
) )
private lazy val eCallInterface: Parser[ECallInterface] = private lazy val eCallInterface: Parser[ECallInterface] =
`icall` ~! `@` ~> fullIdentifier ~ id ~ expr0 ^^ { case ifaceId ~ name ~ body => `call_method` ~! `@` ~> fullIdentifier ~ id ~ expr0 ^^ { case ifaceId ~ name ~ body =>
ECallInterface(interfaceId = ifaceId, methodName = name, value = body) ECallInterface(interfaceId = ifaceId, methodName = name, value = body)
} }

View File

@ -45,7 +45,7 @@ private[parser] object Lexer extends RegexParsers {
"catch" -> `catch`, "catch" -> `catch`,
"to_interface" -> `to_interface`, "to_interface" -> `to_interface`,
"from_interface" -> `from_interface`, "from_interface" -> `from_interface`,
"icall" -> `icall`, "call_method" -> `call_method`,
) )
val token: Parser[Token] = val token: Parser[Token] =

View File

@ -53,7 +53,7 @@ private[parser] object Token {
case object `catch` extends Token case object `catch` extends Token
case object `to_interface` extends Token case object `to_interface` extends Token
case object `from_interface` extends Token case object `from_interface` extends Token
case object `icall` extends Token case object `call_method` extends Token
final case class Id(s: String) extends Token final case class Id(s: String) extends Token
final case class ContractId(s: String) extends Token final case class ContractId(s: String) extends Token

View File

@ -332,9 +332,9 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
EFromAnyException(E, e"anyException"), EFromAnyException(E, e"anyException"),
"throw @Unit @Mod:E exception" -> "throw @Unit @Mod:E exception" ->
EThrow(TUnit, E, e"exception"), EThrow(TUnit, E, e"exception"),
"icall @Mod:I method body" -> "call_method @Mod:I method body" ->
ECallInterface(I.tycon, n"method", e"body"), ECallInterface(I.tycon, n"method", e"body"),
"icall @'-pkgId-':Mod:I method body" -> "call_method @'-pkgId-':Mod:I method body" ->
ECallInterface(I.tycon, n"method", e"body"), ECallInterface(I.tycon, n"method", e"body"),
"to_interface @Mod:T @Mod:I body" -> "to_interface @Mod:T @Mod:I body" ->
EToInterface(T.tycon, I.tycon, e"body"), EToInterface(T.tycon, I.tycon, e"body"),
@ -762,10 +762,10 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
method asParty: Party; method asParty: Party;
method getName: Text; method getName: Text;
choice Sleep (self) (u:Unit) : ContractId Mod:Person choice Sleep (self) (u:Unit) : ContractId Mod:Person
, controllers Cons @Party [icall @Mod:Person asParty this] (Nil @Party) , controllers Cons @Party [call_method @Mod:Person asParty this] (Nil @Party)
to upure @(ContractId Mod:Person) self; to upure @(ContractId Mod:Person) self;
choice @nonConsuming Nap (self) (i : Int64): Int64 choice @nonConsuming Nap (self) (i : Int64): Int64
, controllers Cons @Party [icall @Mod:Person asParty this] (Nil @Party) , controllers Cons @Party [call_method @Mod:Person asParty this] (Nil @Party)
, observers Nil @Party , observers Nil @Party
to upure @Int64 i; to upure @Int64 i;
} ; } ;
@ -785,7 +785,7 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
n"Sleep" -> TemplateChoice( n"Sleep" -> TemplateChoice(
name = n"Sleep", name = n"Sleep",
consuming = true, consuming = true,
controllers = e"Cons @Party [icall @Mod:Person asParty this] (Nil @Party)", controllers = e"Cons @Party [call_method @Mod:Person asParty this] (Nil @Party)",
choiceObservers = None, choiceObservers = None,
selfBinder = n"self", selfBinder = n"self",
argBinder = n"u" -> TUnit, argBinder = n"u" -> TUnit,
@ -795,7 +795,7 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
n"Nap" -> TemplateChoice( n"Nap" -> TemplateChoice(
name = n"Nap", name = n"Nap",
consuming = false, consuming = false,
controllers = e"Cons @Party [icall @Mod:Person asParty this] (Nil @Party)", controllers = e"Cons @Party [call_method @Mod:Person asParty this] (Nil @Party)",
choiceObservers = Some(e"Nil @Party"), choiceObservers = Some(e"Nil @Party"),
selfBinder = n"self", selfBinder = n"self",
argBinder = n"i" -> TInt64, argBinder = n"i" -> TInt64,

View File

@ -456,12 +456,10 @@ private[validation] object Typing {
def checkDefIface(ifaceName: TypeConName, iface: DefInterface): Unit = def checkDefIface(ifaceName: TypeConName, iface: DefInterface): Unit =
iface match { iface match {
case DefInterface(param, fixedChoices, methods, precond) => case DefInterface(param, fixedChoices, methods, precond) =>
fixedChoices.values.foreach(
introExprVar(param, TTyCon(ifaceName)).checkChoice(ifaceName, _)
)
methods.values.foreach(checkIfaceMethod)
val env = introExprVar(param, TTyCon(ifaceName)) val env = introExprVar(param, TTyCon(ifaceName))
env.checkExpr(precond, TBool) env.checkExpr(precond, TBool)
methods.values.foreach(checkIfaceMethod)
fixedChoices.values.foreach(env.checkChoice(ifaceName, _))
} }
def checkIfaceMethod(method: InterfaceMethod): Unit = { def checkIfaceMethod(method: InterfaceMethod): Unit = {

View File

@ -44,20 +44,21 @@
- ensure expression forms have the correct type: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L107) - ensure expression forms have the correct type: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L107)
- ill-formed create command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L133) - ill-formed create command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L133)
- ill-formed create-and-exercise command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L154) - ill-formed create-and-exercise command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L154)
- ill-formed exception definitions are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L1054) - ill-formed exception definitions are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L1409)
- ill-formed exercise command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L138) - ill-formed exercise command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L138)
- ill-formed exercise-by-key command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L145) - ill-formed exercise-by-key command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L145)
- ill-formed expressions are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L408) - ill-formed expressions are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L422)
- ill-formed fetch command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L167) - ill-formed fetch command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L167)
- ill-formed fetch-by-key command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L170) - ill-formed fetch-by-key command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L170)
- ill-formed interfaces are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L1302)
- ill-formed kinds are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L19) - ill-formed kinds are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L19)
- ill-formed lookup command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L175) - ill-formed lookup command is rejected: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L175)
- ill-formed records are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L1196) - ill-formed records are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L1551)
- ill-formed templates are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L815) - ill-formed templates are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L930)
- ill-formed type synonyms applications are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L1175) - ill-formed type synonyms applications are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L1530)
- ill-formed type synonyms definitions are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L1242) - ill-formed type synonyms definitions are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L1597)
- ill-formed types are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L99) - ill-formed types are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L99)
- ill-formed variants are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L1219) - ill-formed variants are rejected: [TypingSpec.scala](daml-lf/validation/src/test/scala/com/digitalasset/daml/lf/validation/TypingSpec.scala#L1574)
- well formed create command is accepted: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L79) - well formed create command is accepted: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L79)
- well formed create-and-exercise command is accepted: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L98) - well formed create-and-exercise command is accepted: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L98)
- well formed exercise command is accepted: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L84) - well formed exercise command is accepted: [CommandPreprocessorSpec.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala#L84)