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

Treat values of type InternalSingleMulti(t, ms) as t for nested dictionaries #699

Merged
merged 3 commits into from
Oct 30, 2023

Conversation

jcp19
Copy link
Contributor

@jcp19 jcp19 commented Oct 28, 2023

Our treatment of expressions with type InternalSingleMulti(t, ms) is very iffy atm, leading to issues like those reported in #694. This PR addresses the issue in part. It allows progress on VerifiedSCION to continue, but I recognize that extending this solution to the entire type system is cumbersome. Ideally, we would have a more systematic way to deal with expressions of this type.

Comment on lines +309 to +351
case (ArrayT(l, _), IntT(_)) =>
val idxOpt = intConstantEval(index)
error(n, s"index $index is out of bounds", !idxOpt.forall(i => i >= 0 && i < l))

case (PointerT(ArrayT(l, _)), IntT(_)) =>
val idxOpt = intConstantEval(index)
error(n, s"index $index is out of bounds", !idxOpt.forall(i => i >= 0 && i < l))

case (SequenceT(_), IntT(_)) =>
noMessages

case (_: SliceT | _: GhostSliceT, IntT(_)) =>
noMessages

case (VariadicT(_), IntT(_)) =>
noMessages

case (StringT, IntT(_)) =>
error(n, "Indexing a string is currently not supported")

case (MapT(key, _), underlyingIdxType) =>
// Assignability in Go is a property between a value and and a type. In Gobra, we model this as a relation
// between two types, which is less precise. Because of this limitation, and with the goal of handling
// untyped literals, we introduce an extra condition here. This makes the type checker of Gobra accept Go
// expressions that are not accepted by the compiler.
val assignableToIdxType = error(n, s"$idxType is not assignable to map key of $key", !assignableTo(idxType, key))
if (assignableToIdxType.nonEmpty) {
error(n, s"$underlyingIdxType is not assignable to map key of $key", !assignableTo(underlyingIdxType, key))
} else {
assignableToIdxType
}

case (StringT, IntT(_)) =>
error(n, "Indexing a string is currently not supported")

case (MapT(key, _), underlyingIdxType) =>
// Assignability in Go is a property between a value and and a type. In Gobra, we model this as a relation
// between two types, which is less precise. Because of this limitation, and with the goal of handling
// untyped literals, we introduce an extra condition here. This makes the type checker of Gobra accept Go
// expressions that are not accepted by the compiler.
val assignableToIdxType = error(n, s"$idxType is not assignable to map key of $key", !assignableTo(idxType, key))
if (assignableToIdxType.nonEmpty) {
error(n, s"$underlyingIdxType is not assignable to map key of $key", !assignableTo(underlyingIdxType, key))
} else {
assignableToIdxType
}
case (MathMapT(key, _), underlyingIdxType) =>
// Assignability in Go is a property between a value and and a type. In Gobra, we model this as a relation
// between two types, which is less precise. Because of this limitation, and with the goal of handling
// untyped literals, we introduce an extra condition here. This makes the type checker of Gobra accept Go
// expressions that are not accepted by the compiler.
val assignableToIdxType = error(n, s"$idxType is not assignable to map key of $key", !assignableTo(idxType, key))
if (assignableToIdxType.nonEmpty) {
error(n, s"$underlyingIdxType is not assignable to map key of $key", !assignableTo(underlyingIdxType, key))
} else {
assignableToIdxType
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is unchanged, I only indented it one level

@jcp19 jcp19 requested a review from Dspil October 28, 2023 20:47
@jcp19 jcp19 merged commit 78e2603 into master Oct 30, 2023
3 checks passed
@jcp19 jcp19 deleted the joao-nested-dicts branch October 30, 2023 10:39
@jcp19
Copy link
Contributor Author

jcp19 commented Oct 30, 2023

@mlimbeck this should solve the problems you are having with dicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants