Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: mojom/mojom_parser/mojom/types.go

Issue 1511353002: New Mojom parser: Fix error message for invalid enum value initailizers. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojom/mojom_parser/mojom/computed_data.go ('k') | mojom/mojom_parser/parser/parsing.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/mojom_parser/mojom/types.go
diff --git a/mojom/mojom_parser/mojom/types.go b/mojom/mojom_parser/mojom/types.go
index f6efc2f26cdcb589ab722a31438d06865cc5f6ce..89b3f292a5f6a70158ae047022c71f34b5638669 100644
--- a/mojom/mojom_parser/mojom/types.go
+++ b/mojom/mojom_parser/mojom/types.go
@@ -953,7 +953,8 @@ func (v *UserValueRef) validateAfterResolution() error {
message = UserErrorMessage(v.scope.file, v.token, message)
return fmt.Errorf(message)
case *EnumValue:
- // An EnumValue is being used as an EnumValue initializer. We do not check this further in this phase.
+ // An EnumValue is being used as an EnumValue initializer.
+ // Below we will check that the two EnumTypes match.
// In ComputeEnumValueIntegers() in computed_data.go we will further validate.
default:
panic(fmt.Sprintf("Unexpected type %T", concreteValue))
@@ -985,12 +986,20 @@ func (v *UserValueRef) validateAfterResolution() error {
switch v.resolvedDeclaredValue.(type) {
case *EnumValue:
// An enum value is being assigned directly to a variable.
- message = fmt.Sprintf("Illegal assignment: The enum value %s may not be assigned to %s of type %s.",
- v.identifier, v.assigneeSpec.Name, assigneeType.TypeName())
+ message = "Illegal assignment: The enum value %s of type %s may not be assigned to %s of type %s."
+ if v.usedAsEnumValueInitializer {
+ // An enum value is being used directly as an initializer.
+ message = "Illegal assignment: The enum value %s of type %s may not be used as an initializer for %s of type %s."
+ }
+ message = fmt.Sprintf(message, v.identifier, concreteValue.enumType.fullyQualifiedName, v.assigneeSpec.Name, assigneeType.TypeName())
default:
// A user-defined constant whose value is an enum value is being assigned to a variable.
- message = fmt.Sprintf("Illegal assignment: %s with the value %v may not be assigned to %s of type %s.",
- v.identifier, concreteValue.fullyQualifiedName, v.assigneeSpec.Name, assigneeType.TypeName())
+ message = "Illegal assignment: %s with the value %v may not be assigned to %s of type %s."
+ if v.usedAsEnumValueInitializer {
+ // A user-defined constant whose value is an enum valu is being used as an initializer.
+ message = "Illegal assignment: %s with the value %v may not be used as an initializer for %s of type %s."
+ }
+ message = fmt.Sprintf(message, v.identifier, concreteValue.fullyQualifiedName, v.assigneeSpec.Name, assigneeType.TypeName())
}
default:
panic(fmt.Sprintf("Unexpected type %T", concreteValue))
« no previous file with comments | « mojom/mojom_parser/mojom/computed_data.go ('k') | mojom/mojom_parser/parser/parsing.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698