-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jcp19
commented
Oct 28, 2023
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 | ||
} |
There was a problem hiding this comment.
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
Dspil
approved these changes
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.