@@ -122,6 +122,9 @@ func (p *parser) parseSchema() (*ast.Schema, error) {
122122 if schema .Namespaces == nil {
123123 schema .Namespaces = ast.Namespaces {}
124124 }
125+ if _ , ok := schema .Namespaces [ns .name ]; ok {
126+ return nil , p .errorf ("namespace %q is declared twice" , ns .name )
127+ }
125128 schema .Namespaces [ns .name ] = ns .ns
126129 } else {
127130 if err := p .parseDecl (annotations , schema ); err != nil {
@@ -260,6 +263,12 @@ func (p *parser) parseEntity(annotations ast.Annotations, schema *ast.Schema) er
260263 schema .Entities = ast.Entities {}
261264 }
262265 for _ , name := range names {
266+ if _ , ok := schema .Entities [name ]; ok {
267+ return p .errorf ("entity %q is declared twice" , name )
268+ }
269+ if _ , ok := schema .Enums [name ]; ok {
270+ return p .errorf ("entity %q is declared twice" , name )
271+ }
263272 schema .Entities [name ] = ast.Entity {
264273 Annotations : annotations ,
265274 ParentTypes : memberOf ,
@@ -302,6 +311,12 @@ func (p *parser) parseEnumEntity(annotations ast.Annotations, names []types.Iden
302311 schema .Enums = ast.Enums {}
303312 }
304313 for _ , name := range names {
314+ if _ , ok := schema .Enums [name ]; ok {
315+ return p .errorf ("entity %q is declared twice" , name )
316+ }
317+ if _ , ok := schema .Entities [name ]; ok {
318+ return p .errorf ("entity %q is declared twice" , name )
319+ }
305320 schema .Enums [name ] = ast.Enum {
306321 Annotations : annotations ,
307322 Values : values ,
@@ -362,6 +377,9 @@ func (p *parser) parseAction(annotations ast.Annotations, schema *ast.Schema) er
362377 schema .Actions = ast.Actions {}
363378 }
364379 for _ , name := range names {
380+ if _ , ok := schema .Actions [name ]; ok {
381+ return p .errorf ("action %q is declared twice" , name )
382+ }
365383 schema .Actions [name ] = ast.Action {
366384 Annotations : annotations ,
367385 Parents : memberOf ,
@@ -396,7 +414,11 @@ func (p *parser) parseTypeDecl(annotations ast.Annotations, schema *ast.Schema)
396414 if schema .CommonTypes == nil {
397415 schema .CommonTypes = ast.CommonTypes {}
398416 }
399- schema .CommonTypes [types .Ident (name )] = ast.CommonType {
417+ ident := types .Ident (name )
418+ if _ , ok := schema .CommonTypes [ident ]; ok {
419+ return p .errorf ("type %q is declared twice" , name )
420+ }
421+ schema .CommonTypes [ident ] = ast.CommonType {
400422 Annotations : annotations ,
401423 Type : typ ,
402424 }
0 commit comments