Merge remote-tracking branch 'aosp/upstream'.

* aosp/upstream:
  Make sure all modules have a name. (#226)

Bug: 34281936
Test: context_test.go
Change-Id: I8e3d06ad027071f19f5b11f2cb9b33997d2642a0
diff --git a/context.go b/context.go
index 3c248ab..93212f0 100644
--- a/context.go
+++ b/context.go
@@ -1292,6 +1292,14 @@
 
 func (c *Context) addModule(module *moduleInfo) []error {
 	name := module.logicModule.Name()
+	if name == "" {
+		return []error{
+			&BlueprintError{
+				Err: fmt.Errorf("property 'name' is missing from a module"),
+				Pos: module.pos,
+			},
+		}
+	}
 	c.moduleInfo[module.logicModule] = module
 
 	group := &moduleGroup{
diff --git a/context_test.go b/context_test.go
index bc21a1c..0d783dc 100644
--- a/context_test.go
+++ b/context_test.go
@@ -482,3 +482,29 @@
 	}
 
 }
+
+func TestParseFailsForModuleWithoutName(t *testing.T) {
+	ctx := NewContext()
+	ctx.MockFileSystem(map[string][]byte{
+		"Blueprints": []byte(`
+			foo_module {
+			    name: "A",
+			}
+			
+			bar_module {
+			    deps: ["A"],
+			}
+		`),
+	})
+	ctx.RegisterModuleType("foo_module", newFooModule)
+	ctx.RegisterModuleType("bar_module", newBarModule)
+
+	_, errs := ctx.ParseBlueprintsFiles("Blueprints")
+
+	expectedErrs := []error{
+		errors.New(`Blueprints:6:4: property 'name' is missing from a module`),
+	}
+	if fmt.Sprintf("%s", expectedErrs) != fmt.Sprintf("%s", errs) {
+		t.Errorf("Incorrect errors; expected:\n%s\ngot:\n%s", expectedErrs, errs)
+	}
+}