mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-19 16:57:40 +03:00
Fix NonUnitStatements in daml-lf code (#11145)
* build daml-lf/* with lf_scalacopts_stricter; and fix NonUnitStatements fix daml-lf/archive CHANGELOG_BEGIN CHANGELOG_END fix daml-lf/data/ fix daml-lf/engine fixes for scala 2.12 data-scalacheck, interface, kv-transaction-support: switch on; nothing to do * daml-lf/parser -- switch on; nothing to do * daml-lf/validation : switch on lf_scalacopts_stricter & fix wartremover:NonUnitStatements * lf_scalacopts_stricter in daml-lf/transaction-test-lib * lf_scalacopts_stricter in daml-lf/scenario-interpreter
This commit is contained in:
parent
06834936bc
commit
67d4011fcd
@ -11,6 +11,7 @@ load(
|
||||
"da_scala_library",
|
||||
"da_scala_test_suite",
|
||||
"lf_scalacopts",
|
||||
"lf_scalacopts_stricter",
|
||||
"silencer_plugin",
|
||||
)
|
||||
load("//daml-lf/language:daml-lf.bzl", "LF_MAJOR_VERSIONS", "PROTO_LF_VERSIONS", "lf_version_package", "mangle_for_java")
|
||||
@ -108,7 +109,7 @@ da_scala_library(
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_scala_lang_modules_scala_collection_compat",
|
||||
],
|
||||
scalacopts = lf_scalacopts,
|
||||
scalacopts = lf_scalacopts_stricter,
|
||||
tags = ["maven_coordinates=com.daml:daml-lf-archive-reader:__VERSION__"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
@ -116,6 +117,7 @@ da_scala_library(
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/language",
|
||||
"//libs-scala/nameof",
|
||||
"//libs-scala/scala-utils",
|
||||
"@maven//:com_google_protobuf_protobuf_java",
|
||||
],
|
||||
)
|
||||
|
@ -13,6 +13,7 @@ import com.daml.lf.language.Ast._
|
||||
import com.daml.lf.language.Util._
|
||||
import com.daml.lf.language.{LanguageVersion => LV}
|
||||
import com.daml.nameof.NameOf
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
import scala.Ordering.Implicits.infixOrderingOps
|
||||
import scala.collection.compat._
|
||||
@ -167,7 +168,7 @@ private[archive] class DecodeV1(minor: LV.Minor) {
|
||||
private val deps = mutable.Set.empty[PackageId]
|
||||
def markDependency(pkgId: PackageId): Unit =
|
||||
if (pkgId != self)
|
||||
deps += pkgId
|
||||
discard(deps += pkgId)
|
||||
def getDependencies: Set[PackageId] = deps.toSet
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.daml.daml_lf_dev.{DamlLf, DamlLf1}
|
||||
import com.daml.lf.data.Ref.PackageId
|
||||
import com.daml.lf.language.{Ast, LanguageVersion}
|
||||
import com.daml.nameof.NameOf
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import com.google.protobuf.CodedInputStream
|
||||
|
||||
import scala.util.Using
|
||||
@ -50,7 +51,7 @@ package object archive {
|
||||
// just set the recursion limit
|
||||
private[this] val Base: GenReader[CodedInputStream] =
|
||||
new GenReader[CodedInputStream]({ cos =>
|
||||
cos.setRecursionLimit(PROTOBUF_RECURSION_LIMIT)
|
||||
discard(cos.setRecursionLimit(PROTOBUF_RECURSION_LIMIT))
|
||||
Right(cos)
|
||||
})
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
load(
|
||||
"//bazel_tools:scala.bzl",
|
||||
"da_scala_library",
|
||||
"lf_scalacopts",
|
||||
"lf_scalacopts_stricter",
|
||||
)
|
||||
load("@scala_version//:index.bzl", "scala_version_suffix")
|
||||
|
||||
@ -18,7 +18,7 @@ da_scala_library(
|
||||
"@maven//:org_scalacheck_scalacheck",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
],
|
||||
scalacopts = lf_scalacopts,
|
||||
scalacopts = lf_scalacopts_stricter,
|
||||
tags = ["maven_coordinates=com.daml:daml-lf-data-scalacheck:__VERSION__"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
|
@ -6,6 +6,7 @@ load(
|
||||
"da_scala_library",
|
||||
"da_scala_test",
|
||||
"lf_scalacopts",
|
||||
"lf_scalacopts_stricter",
|
||||
"silencer_plugin",
|
||||
)
|
||||
load("@scala_version//:index.bzl", "scala_major_version", "scala_version_suffix")
|
||||
@ -24,7 +25,7 @@ da_scala_library(
|
||||
"@maven//:org_scala_lang_modules_scala_collection_compat",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
],
|
||||
scalacopts = lf_scalacopts + [
|
||||
scalacopts = lf_scalacopts_stricter + [
|
||||
"-P:silencer:lineContentFilters=import ImmArraySeq.Implicits._",
|
||||
],
|
||||
tags = ["maven_coordinates=com.daml:daml-lf-data:__VERSION__"],
|
||||
@ -33,6 +34,7 @@ da_scala_library(
|
||||
],
|
||||
deps = [
|
||||
"//libs-scala/logging-entries",
|
||||
"//libs-scala/scala-utils",
|
||||
"@maven//:com_google_guava_guava",
|
||||
"@maven//:com_google_protobuf_protobuf_java",
|
||||
"@maven//:org_slf4j_slf4j_api",
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
package com.daml.lf.data
|
||||
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
import scala.annotation.unchecked.uncheckedVariance
|
||||
import scala.collection.generic.{
|
||||
CanBuildFrom,
|
||||
@ -23,8 +25,7 @@ abstract class AbstractImmArraySeq[+A](array: ImmArray[A])
|
||||
override final def companion: GenericCompanion[ImmArraySeq] = ImmArraySeq
|
||||
|
||||
override final def copyToArray[B >: A](xs: Array[B], dstStart: Int, dstLen: Int): Unit = {
|
||||
array.copyToArray(xs, dstStart, dstLen)
|
||||
()
|
||||
discard(array.copyToArray(xs, dstStart, dstLen))
|
||||
}
|
||||
|
||||
override final def map[B, That](
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
package com.daml.lf.data
|
||||
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
import scala.collection.IterableLike
|
||||
import scala.collection.generic.CanBuildFrom
|
||||
import scala.annotation.tailrec
|
||||
@ -20,7 +22,7 @@ private[daml] object LawlessTraversals {
|
||||
if (i.hasNext) f(i.next) match {
|
||||
case Left(b) => Left(b)
|
||||
case Right(c) =>
|
||||
that += c
|
||||
discard(that += c)
|
||||
lp()
|
||||
}
|
||||
else Right(that.result)
|
||||
|
@ -19,8 +19,9 @@ abstract class ImmArrayInstances extends scala.collection.IterableFactory[ImmArr
|
||||
case otherwise =>
|
||||
val builder = newBuilder[A]
|
||||
builder.sizeHint(otherwise)
|
||||
builder.addAll(otherwise)
|
||||
builder.result()
|
||||
builder
|
||||
.addAll(otherwise)
|
||||
.result()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
package com.daml.lf.data
|
||||
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.BuildFrom
|
||||
|
||||
@ -20,7 +22,7 @@ private[daml] object LawlessTraversals {
|
||||
if (i.hasNext) f(i.next()) match {
|
||||
case Left(b) => Left(b)
|
||||
case Right(c) =>
|
||||
that += c
|
||||
discard(that += c)
|
||||
lp()
|
||||
}
|
||||
else Right(that.result())
|
||||
|
@ -2,6 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
package com.daml.lf.data
|
||||
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
import java.io.{StringReader, StringWriter}
|
||||
|
||||
import com.google.common.io.{BaseEncoding, ByteStreams}
|
||||
@ -162,7 +164,7 @@ private object HexStringModuleImpl extends StringModuleImpl with HexStringModule
|
||||
override def encode(a: Bytes): T = {
|
||||
val writer = new StringWriter()
|
||||
val os = baseEncode.encodingStream(writer)
|
||||
ByteStreams.copy(a.toInputStream, os)
|
||||
discard[Long](ByteStreams.copy(a.toInputStream, os))
|
||||
writer.toString
|
||||
}
|
||||
|
||||
@ -230,7 +232,7 @@ private final class ConcatenableMatchingStringModule(
|
||||
|
||||
override def concat(s: T, ss: T*): Either[String, T] = {
|
||||
val b = new StringBuilder
|
||||
b ++= s
|
||||
discard(b ++= s)
|
||||
ss.foreach(b ++= _)
|
||||
if (b.length <= maxLength) Right(b.result()) else Left(s"id ${b.result()} too Long")
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
package com.daml.lf.data
|
||||
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
import ScalazEqual.{equalBy, orderBy, toIterableForScalazInstances}
|
||||
import scalaz.syntax.applicative._
|
||||
import scalaz.{Applicative, Equal, Foldable, Order, Traverse}
|
||||
@ -265,7 +267,7 @@ final class ImmArray[+A] private (
|
||||
var i = 0
|
||||
while (i < length) {
|
||||
val a = uncheckedGet(i)
|
||||
if (f.isDefinedAt(a)) builder += f(a)
|
||||
if (f.isDefinedAt(a)) discard(builder += f(a))
|
||||
i += 1
|
||||
}
|
||||
builder.result()
|
||||
|
@ -4,6 +4,8 @@
|
||||
package com.daml.lf
|
||||
package data
|
||||
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
object Ref {
|
||||
|
||||
val IdString: IdString = new IdStringImpl
|
||||
@ -82,13 +84,13 @@ object Ref {
|
||||
s.codePoints()
|
||||
.forEach(ch => {
|
||||
if (ch == splitCodepoint) {
|
||||
segments += currentString.toString
|
||||
discard(segments += currentString.toString)
|
||||
currentString.setLength(0)
|
||||
} else {
|
||||
val _ = currentString.appendCodePoint(ch)
|
||||
}
|
||||
})
|
||||
segments += currentString.toString
|
||||
discard(segments += currentString.toString)
|
||||
segments.result()
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,8 @@ package data
|
||||
|
||||
import java.security.MessageDigest
|
||||
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
import com.google.common.io.BaseEncoding
|
||||
import com.google.protobuf.ByteString
|
||||
import scalaz.Order
|
||||
@ -28,7 +30,7 @@ object Utf8 {
|
||||
while (i < len) {
|
||||
// if s(i) is a high surrogate the current codepoint uses 2 chars
|
||||
val next = if (s(i).isHighSurrogate) i + 2 else i + 1
|
||||
arr += s.substring(i, next)
|
||||
discard(arr += s.substring(i, next))
|
||||
i = next
|
||||
}
|
||||
arr.result()
|
||||
@ -90,8 +92,8 @@ object Utf8 {
|
||||
} else if (Character.MAX_VALUE < cp && cp <= Character.MAX_CODE_POINT) {
|
||||
// cp is from one of the Supplementary Plans,
|
||||
// then it needs 2 UTF16 Chars to be encoded.
|
||||
builder += Character.highSurrogate(cp.toInt)
|
||||
builder += Character.lowSurrogate(cp.toInt)
|
||||
discard(builder += Character.highSurrogate(cp.toInt))
|
||||
discard(builder += Character.lowSurrogate(cp.toInt))
|
||||
} else {
|
||||
// cp is not a legal Unicode code point
|
||||
illegalCodePoint = Some(cp)
|
||||
|
@ -7,6 +7,7 @@ load(
|
||||
"da_scala_test",
|
||||
"da_scala_test_suite",
|
||||
"lf_scalacopts",
|
||||
"lf_scalacopts_stricter",
|
||||
)
|
||||
|
||||
da_scala_library(
|
||||
@ -16,7 +17,7 @@ da_scala_library(
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_typelevel_paiges_core",
|
||||
],
|
||||
scalacopts = lf_scalacopts,
|
||||
scalacopts = lf_scalacopts_stricter,
|
||||
tags = ["maven_coordinates=com.daml:daml-lf-engine:__VERSION__"],
|
||||
versioned_scala_deps = {
|
||||
"2.12": ["@maven//:org_scala_lang_modules_scala_collection_compat"],
|
||||
@ -29,6 +30,7 @@ da_scala_library(
|
||||
"//daml-lf/transaction",
|
||||
"//daml-lf/validation",
|
||||
"//libs-scala/nameof",
|
||||
"//libs-scala/scala-utils",
|
||||
"@maven//:com_google_protobuf_protobuf_java",
|
||||
],
|
||||
)
|
||||
|
@ -12,6 +12,7 @@ import com.daml.lf.language.Ast.{Package, PackageSignature}
|
||||
import com.daml.lf.language.{PackageInterface, Util => AstUtil}
|
||||
import com.daml.lf.speedy.Compiler
|
||||
import com.daml.nameof.NameOf
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
import scala.jdk.CollectionConverters._
|
||||
import scala.collection.concurrent.{Map => ConcurrentMap}
|
||||
@ -137,7 +138,7 @@ private[lf] final class ConcurrentCompiledPackages(compilerConfig: Compiler.Conf
|
||||
val deps = pkg.directDeps.foldLeft(pkg.directDeps) { case (deps, dependency) =>
|
||||
deps union packageDeps.get(dependency)
|
||||
}
|
||||
packageDeps.put(pkgId, deps)
|
||||
discard(packageDeps.put(pkgId, deps))
|
||||
signatures.put(pkgId, pkgSignature)
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import java.nio.file.Files
|
||||
import com.daml.lf.language.{PackageInterface, LanguageVersion, LookupError, StablePackages}
|
||||
import com.daml.lf.validation.Validation
|
||||
import com.daml.nameof.NameOf
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
/** Allows for evaluating [[Commands]] and validating [[Transaction]]s.
|
||||
* <p>
|
||||
@ -335,9 +336,9 @@ class Engine(val config: EngineConfig = Engine.StableConfig) {
|
||||
case SResultError(err) =>
|
||||
err match {
|
||||
case SError.SErrorCrash(where, reason) =>
|
||||
Error.Interpretation.Internal(where, reason)
|
||||
discard[Error.Interpretation.Internal](Error.Interpretation.Internal(where, reason))
|
||||
case SError.SErrorDamlException(error) =>
|
||||
Error.Interpretation.DamlException(error)
|
||||
discard[Error.Interpretation.DamlException](Error.Interpretation.DamlException(error))
|
||||
}
|
||||
case SResultNeedPackage(pkgId, context, callback) =>
|
||||
return Result.needPackage(
|
||||
@ -367,7 +368,7 @@ class Engine(val config: EngineConfig = Engine.StableConfig) {
|
||||
return ResultNeedKey(
|
||||
gk,
|
||||
{ result =>
|
||||
cb(result)
|
||||
discard[Boolean](cb(result))
|
||||
interpretLoop(machine, time)
|
||||
},
|
||||
)
|
||||
|
@ -10,6 +10,7 @@ import com.daml.lf.transaction.NodeId
|
||||
import com.daml.lf.data.ImmArray
|
||||
import com.daml.lf.value.Value
|
||||
import com.daml.lf.value.Value.ContractId
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
// --------------------------
|
||||
// Emitted events for the API
|
||||
@ -87,12 +88,14 @@ object Event {
|
||||
evt match {
|
||||
case ce: CreateEvent =>
|
||||
if (f(ce)) {
|
||||
liveEvts += (evtid -> ce)
|
||||
discard(liveEvts += (evtid -> ce))
|
||||
}
|
||||
case ee: ExerciseEvent =>
|
||||
if (f(ee)) {
|
||||
go(ee.children)
|
||||
liveEvts += (evtid -> ee.copy(children = ee.children.filter(liveEvts.contains)))
|
||||
discard(
|
||||
liveEvts += (evtid -> ee.copy(children = ee.children.filter(liveEvts.contains)))
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -8,6 +8,7 @@ package preprocessing
|
||||
import com.daml.lf.data._
|
||||
import com.daml.lf.language.Ast
|
||||
import com.daml.lf.value.Value
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
@ -129,7 +130,7 @@ private[lf] final class CommandPreprocessor(
|
||||
case command.FetchCommand(templateId, coid) =>
|
||||
// TODO https://github.com/digital-asset/daml/issues/10810
|
||||
// -- handle the case where templateId is an interface
|
||||
handleLookup(interface.lookupTemplate(templateId))
|
||||
discard[Ast.TemplateSignature](handleLookup(interface.lookupTemplate(templateId)))
|
||||
val cid = valueTranslator.unsafeTranslateCid(coid)
|
||||
speedy.Command.Fetch(templateId, cid)
|
||||
case command.FetchByKeyCommand(templateId, key) =>
|
||||
|
@ -6,6 +6,7 @@ load(
|
||||
"da_scala_library",
|
||||
"da_scala_test",
|
||||
"lf_scalacopts",
|
||||
"lf_scalacopts_stricter",
|
||||
"silencer_plugin",
|
||||
)
|
||||
|
||||
@ -19,7 +20,7 @@ da_scala_library(
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_scala_lang_modules_scala_collection_compat",
|
||||
],
|
||||
scalacopts = lf_scalacopts,
|
||||
scalacopts = lf_scalacopts_stricter,
|
||||
tags = ["maven_coordinates=com.daml:daml-lf-interface:__VERSION__"],
|
||||
visibility = [
|
||||
"//daml-assistant/daml-sdk:__subpackages__",
|
||||
|
@ -6,12 +6,13 @@ load(
|
||||
"da_scala_library",
|
||||
"da_scala_test_suite",
|
||||
"lf_scalacopts",
|
||||
"lf_scalacopts_stricter",
|
||||
)
|
||||
|
||||
da_scala_library(
|
||||
name = "kv-transaction-support",
|
||||
srcs = glob(["src/main/**/*.scala"]),
|
||||
scalacopts = lf_scalacopts,
|
||||
scalacopts = lf_scalacopts_stricter,
|
||||
tags = ["maven_coordinates=com.daml:daml-lf-kv-transaction-support:__VERSION__"],
|
||||
visibility = ["//ledger/participant-state/kvutils:__subpackages__"],
|
||||
deps = [
|
||||
|
@ -6,6 +6,7 @@ load(
|
||||
"da_scala_library",
|
||||
"da_scala_test",
|
||||
"lf_scalacopts",
|
||||
"lf_scalacopts_stricter",
|
||||
"silencer_plugin",
|
||||
)
|
||||
|
||||
@ -19,7 +20,7 @@ da_scala_library(
|
||||
"@maven//:org_scala_lang_modules_scala_parser_combinators",
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
],
|
||||
scalacopts = lf_scalacopts + [
|
||||
scalacopts = lf_scalacopts_stricter + [
|
||||
"-P:silencer:lineContentFilters=standardInterpolator",
|
||||
],
|
||||
visibility = [
|
||||
|
@ -8,6 +8,7 @@ load(
|
||||
"da_scala_test",
|
||||
"da_scala_test_suite",
|
||||
"lf_scalacopts",
|
||||
"lf_scalacopts_stricter",
|
||||
)
|
||||
load(
|
||||
"//rules_daml:daml.bzl",
|
||||
@ -20,6 +21,7 @@ da_scala_library(
|
||||
srcs = glob(["src/main/**/*.scala"]),
|
||||
main_class = "com.daml.lf.speedy.Main",
|
||||
scala_deps = ["@maven//:org_typelevel_paiges_core"],
|
||||
scalacopts = lf_scalacopts_stricter,
|
||||
tags = ["maven_coordinates=com.daml:daml-lf-scenario-interpreter:__VERSION__"],
|
||||
versioned_scala_deps = {"2.12": ["@maven//:org_scalaz_scalaz_core"]},
|
||||
visibility = [
|
||||
|
@ -4,7 +4,7 @@
|
||||
load(
|
||||
"//bazel_tools:scala.bzl",
|
||||
"da_scala_library",
|
||||
"lf_scalacopts",
|
||||
"lf_scalacopts_stricter",
|
||||
"silencer_plugin",
|
||||
)
|
||||
load("@scala_version//:index.bzl", "scala_version_suffix")
|
||||
@ -23,7 +23,7 @@ da_scala_library(
|
||||
"@maven//:org_scalaz_scalaz_scalacheck_binding",
|
||||
"@maven//:org_scala_lang_modules_scala_collection_compat",
|
||||
],
|
||||
scalacopts = lf_scalacopts + [
|
||||
scalacopts = lf_scalacopts_stricter + [
|
||||
"-P:silencer:lineContentFilters=import elt.injshrink",
|
||||
# Forced upon us by Shrink
|
||||
"-P:silencer:lineContentFilters=Stream.empty",
|
||||
|
@ -6,6 +6,7 @@ load(
|
||||
"da_scala_library",
|
||||
"da_scala_test",
|
||||
"lf_scalacopts",
|
||||
"lf_scalacopts_stricter",
|
||||
"silencer_plugin",
|
||||
)
|
||||
|
||||
@ -16,7 +17,7 @@ da_scala_library(
|
||||
"@maven//:org_scalaz_scalaz_core",
|
||||
"@maven//:org_scala_lang_modules_scala_collection_compat",
|
||||
],
|
||||
scalacopts = lf_scalacopts,
|
||||
scalacopts = lf_scalacopts_stricter,
|
||||
tags = ["maven_coordinates=com.daml:daml-lf-validation:__VERSION__"],
|
||||
visibility = [
|
||||
"//compiler/scenario-service:__subpackages__",
|
||||
@ -26,6 +27,7 @@ da_scala_library(
|
||||
deps = [
|
||||
"//daml-lf/data",
|
||||
"//daml-lf/language",
|
||||
"//libs-scala/scala-utils",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -11,6 +11,7 @@ import com.daml.lf.language.{LanguageVersion, PackageInterface}
|
||||
import com.daml.lf.validation.AlphaEquiv._
|
||||
import com.daml.lf.validation.Util._
|
||||
import com.daml.lf.validation.iterable.TypeIterable
|
||||
import com.daml.scalautil.Statement.discard
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
@ -21,8 +22,7 @@ private[validation] object Typing {
|
||||
/* Typing */
|
||||
|
||||
private def checkUniq[A](xs: Iterator[A], mkError: A => ValidationError): Unit = {
|
||||
(xs foldLeft Set.empty[A])((acc, x) => if (acc(x)) throw mkError(x) else acc + x)
|
||||
()
|
||||
discard((xs foldLeft Set.empty[A])((acc, x) => if (acc(x)) throw mkError(x) else acc + x))
|
||||
}
|
||||
|
||||
private def kindOfBuiltin(bType: BuiltinType): Kind = bType match {
|
||||
@ -601,8 +601,7 @@ private[validation] object Typing {
|
||||
val (exprFieldNames, fieldExprs) = recordExpr.unzip
|
||||
val (typeFieldNames, fieldTypes) = recordType.unzip
|
||||
if (exprFieldNames != typeFieldNames) throw EFieldMismatch(ctx, typ, recordExpr)
|
||||
(fieldExprs zip fieldTypes).map((checkExpr _).tupled)
|
||||
()
|
||||
(fieldExprs zip fieldTypes).foreach((checkExpr _).tupled)
|
||||
case _ =>
|
||||
throw EExpectedRecordType(ctx, typ)
|
||||
}
|
||||
@ -852,7 +851,7 @@ private[validation] object Typing {
|
||||
private def typeOfLet(binding: Binding, body: Expr): Type = binding match {
|
||||
case Binding(Some(vName), typ0, expr) =>
|
||||
checkType(typ0, KStar)
|
||||
val typ1 = checkExpr(expr, typ0)
|
||||
val typ1 = resolveExprType(expr, typ0)
|
||||
introExprVar(vName, typ1).typeOf(body)
|
||||
case Binding(_, _, bound @ _) =>
|
||||
typeOf(body)
|
||||
@ -861,7 +860,7 @@ private[validation] object Typing {
|
||||
private def checkCons(elemType: Type, front: ImmArray[Expr], tailExpr: Expr): Unit = {
|
||||
checkType(elemType, KStar)
|
||||
if (front.isEmpty) throw EEmptyConsFront(ctx)
|
||||
front.map(checkExpr(_, elemType))
|
||||
front.foreach(checkExpr(_, elemType))
|
||||
checkExpr(tailExpr, TList(elemType))
|
||||
()
|
||||
}
|
||||
@ -897,7 +896,7 @@ private[validation] object Typing {
|
||||
}
|
||||
|
||||
private def typeOfCreate(tpl: TypeConName, arg: Expr): Type = {
|
||||
handleLookup(ctx, interface.lookupTemplate(tpl))
|
||||
discard(handleLookup(ctx, interface.lookupTemplate(tpl)))
|
||||
checkExpr(arg, TTyCon(tpl))
|
||||
TUpdate(TContractId(TTyCon(tpl)))
|
||||
}
|
||||
@ -944,19 +943,19 @@ private[validation] object Typing {
|
||||
}
|
||||
|
||||
private def typeOfFetch(tpl: TypeConName, cid: Expr): Type = {
|
||||
handleLookup(ctx, interface.lookupTemplate(tpl))
|
||||
discard(handleLookup(ctx, interface.lookupTemplate(tpl)))
|
||||
checkExpr(cid, TContractId(TTyCon(tpl)))
|
||||
TUpdate(TTyCon(tpl))
|
||||
}
|
||||
|
||||
private def typeOfFetchInterface(tpl: TypeConName, cid: Expr): Type = {
|
||||
handleLookup(ctx, interface.lookupInterface(tpl))
|
||||
discard(handleLookup(ctx, interface.lookupInterface(tpl)))
|
||||
checkExpr(cid, TContractId(TTyCon(tpl)))
|
||||
TUpdate(TTyCon(tpl))
|
||||
}
|
||||
|
||||
private def checkImplements(tpl: TypeConName, iface: TypeConName): Unit = {
|
||||
handleLookup(ctx, interface.lookupInterface(iface))
|
||||
discard(handleLookup(ctx, interface.lookupInterface(iface)))
|
||||
val template = handleLookup(ctx, interface.lookupTemplate(tpl))
|
||||
if (!template.implements.contains(iface))
|
||||
throw ETemplateDoesNotImplementInterface(ctx, tpl, iface)
|
||||
@ -1049,7 +1048,7 @@ private[validation] object Typing {
|
||||
checkExpr(name, TText)
|
||||
TScenario(TParty)
|
||||
case ScenarioEmbedExpr(typ, exp) =>
|
||||
checkExpr(exp, TScenario(typ))
|
||||
resolveExprType(exp, TScenario(typ))
|
||||
}
|
||||
|
||||
// checks that typ contains neither variables, nor quantifiers, nor synonyms
|
||||
@ -1070,8 +1069,7 @@ private[validation] object Typing {
|
||||
private def checkExceptionType(typ: Type): Unit = {
|
||||
typ match {
|
||||
case TTyCon(tyCon) =>
|
||||
handleLookup(ctx, interface.lookupException(tyCon))
|
||||
()
|
||||
discard(handleLookup(ctx, interface.lookupException(tyCon)))
|
||||
case _ =>
|
||||
throw EExpectedExceptionType(ctx, typ)
|
||||
}
|
||||
@ -1183,13 +1181,17 @@ private[validation] object Typing {
|
||||
typ
|
||||
}
|
||||
|
||||
def checkExpr(expr: Expr, typ0: Type): Type = {
|
||||
def resolveExprType(expr: Expr, typ0: Type): Type = {
|
||||
val exprType = typeOf(expr)
|
||||
val typ = expandTypeSynonyms(typ0)
|
||||
if (!alphaEquiv(exprType, typ))
|
||||
throw ETypeMismatch(ctx, foundType = exprType, expectedType = typ, expr = Some(expr))
|
||||
exprType
|
||||
}
|
||||
|
||||
def checkExpr(expr: Expr, typ0: Type): Unit = {
|
||||
discard[Type](resolveExprType(expr, typ0))
|
||||
}
|
||||
}
|
||||
|
||||
/* Utils */
|
||||
|
Loading…
Reference in New Issue
Block a user