Skip to content

Commit

Permalink
LF: Test scala interface type checking (#11833)
Browse files Browse the repository at this point in the history
CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da authored Nov 24, 2021
1 parent 5f52f00 commit 86da6e8
Show file tree
Hide file tree
Showing 7 changed files with 655 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private[parser] class ExprParser[P](parserParameters: ParserParameters[P]) {
)

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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private[parser] object Lexer extends RegexParsers {
"catch" -> `catch`,
"to_interface" -> `to_interface`,
"from_interface" -> `from_interface`,
"icall" -> `icall`,
"call_method" -> `call_method`,
)

val token: Parser[Token] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private[parser] object Token {
case object `catch` extends Token
case object `to_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 ContractId(s: String) extends Token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
EFromAnyException(E, e"anyException"),
"throw @Unit @Mod: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"),
"icall @'-pkgId-':Mod:I method body" ->
"call_method @'-pkgId-':Mod:I method body" ->
ECallInterface(I.tycon, n"method", e"body"),
"to_interface @Mod:T @Mod:I body" ->
EToInterface(T.tycon, I.tycon, e"body"),
Expand Down Expand Up @@ -762,10 +762,10 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
method asParty: Party;
method getName: Text;
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;
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
to upure @Int64 i;
} ;
Expand All @@ -785,7 +785,7 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
n"Sleep" -> TemplateChoice(
name = n"Sleep",
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,
selfBinder = n"self",
argBinder = n"u" -> TUnit,
Expand All @@ -795,7 +795,7 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
n"Nap" -> TemplateChoice(
name = n"Nap",
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"),
selfBinder = n"self",
argBinder = n"i" -> TInt64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,10 @@ private[validation] object Typing {
def checkDefIface(ifaceName: TypeConName, iface: DefInterface): Unit =
iface match {
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))
env.checkExpr(precond, TBool)
methods.values.foreach(checkIfaceMethod)
fixedChoices.values.foreach(env.checkChoice(ifaceName, _))
}

def checkIfaceMethod(method: InterfaceMethod): Unit = {
Expand Down
Loading

0 comments on commit 86da6e8

Please sign in to comment.