Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the bug in type checking uninterpreted types #1792

Merged
merged 3 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix the bug in type checking uninterpreted types
  • Loading branch information
konnov committed May 20, 2022
commit e99605217fffaa86207cafa0ec6829c35b39e777
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ object ModelValueHandler {
*/
private val matchRegex: Regex = raw"([a-zA-Z0-9_]+)_OF_([A-Z_][A-Z0-9_]*)".r

/**
* Is the supplied string encoding a model value.
*
* @param text
* a string to test
* @return
* true, if the string encodes a model value
*/
def isModelValue(text: String): Boolean = {
typeAndIndex(text).isDefined
}

/**
* Returns the type of `s`. If `s` follows the pattern for model values, its type is `ConstT1(_)`, otherwise is is a
* regular string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package at.forsyte.apalache.tla.typecheck.etc
import at.forsyte.apalache.io.annotations.store.{findAnnotation, AnnotationStore}
import at.forsyte.apalache.io.annotations.{Annotation, AnnotationStr, StandardAnnotations}
import at.forsyte.apalache.io.typecheck.parser.{DefaultType1Parser, Type1ParseError}
import at.forsyte.apalache.tla.lir._
import at.forsyte.apalache.tla.lir.oper._
import at.forsyte.apalache.tla.lir.values._
import at.forsyte.apalache.tla.lir._
import at.forsyte.apalache.tla.typecheck._
import com.typesafe.scalalogging.LazyLogging

Expand Down Expand Up @@ -968,6 +968,12 @@ class ToEtcExpr(
(SparseTupT1(fieldNo.toInt -> a), IntT1(), a),
)

case ValEx(TlaStr(fieldName)) if ModelValueHandler.isModelValue(fieldName) =>
// fieldName encodes a constant of an uninterpreted sort
val a = varPool.fresh
val uninterpretedType = ModelValueHandler.modelValueOrString(fieldName)
Seq((FunT1(uninterpretedType, a), uninterpretedType, a))

case ValEx(TlaStr(fieldName)) =>
// f[s] or [f EXCEPT ![s] = ...], where s is a string literal
val a = varPool.fresh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,17 @@ class TestToEtcExpr extends AnyFunSuite with BeforeAndAfterEach with ToEtcExprBa
assert(gen(access).explain(List(), List()).isDefined)
}

test("""f["1_OF_A"]""") {
// it should always be a function, because A is an uninterpreted type
val fun = Seq(parser("((A -> a), A) => a"))
val expected = mkUniqApp(fun, mkUniqName("f"), mkUniqConst(ConstT1("A")))
val access = tla.appFun(tla.name("f"), tla.str("1_OF_A"))
assert(expected == gen(access))

// Has custom type error message
assert(gen(access).explain(List(), List()).isDefined)
}

test("DOMAIN f") {
// DOMAIN is applied to one of the four objects: a function, a sequence, a record, or a sparse tuple
val types = Seq(parser("(a -> b) => Set(a)"), parser("Seq(c) => Set(Int)"), parser("[] => Set(Str)"),
Expand Down