reflect/protodesc: check file imports by name

Weak imports are added to Imports as placeholders even if they can be
found in the Files registry, so we have to look at the name rather than
the actual FileDescriptor.

Change-Id: I28f62e945f233119014e5e8cb1bcbde7dca831a7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/175897
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/reflect/protodesc/protodesc_test.go b/reflect/protodesc/protodesc_test.go
index b82078e..9da39a8 100644
--- a/reflect/protodesc/protodesc_test.go
+++ b/reflect/protodesc/protodesc_test.go
@@ -553,6 +553,41 @@
 				}},
 			}},
 		},
+	}, {
+		name: "external type from weak import",
+		deps: []*descriptorpb.FileDescriptorProto{{
+			Name:    scalar.String("weak.proto"),
+			Syntax:  scalar.String("proto2"),
+			Package: scalar.String("foo"),
+			MessageType: []*descriptorpb.DescriptorProto{{
+				Name: scalar.String("WeakMessage"),
+			}},
+		}},
+		fd: &descriptorpb.FileDescriptorProto{
+			Name:           scalar.String("external-type-from-weak-import.proto"),
+			Syntax:         scalar.String("proto2"),
+			Package:        scalar.String("bar"),
+			Dependency:     []string{"weak.proto"},
+			WeakDependency: []int32{0},
+			MessageType: []*descriptorpb.DescriptorProto{{
+				Name: scalar.String("Bar"),
+				Field: []*descriptorpb.FieldDescriptorProto{{
+					Name:   scalar.String("id"),
+					Number: scalar.Int32(1),
+					Label:  descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
+					Type:   descriptorpb.FieldDescriptorProto_TYPE_STRING.Enum(),
+				}, {
+					Name:     scalar.String("weak_message"),
+					Number:   scalar.Int32(2),
+					Label:    descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(),
+					Type:     descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
+					TypeName: scalar.String(".foo.WeakMessage"),
+					Options: &descriptorpb.FieldOptions{
+						Weak: scalar.Bool(true),
+					},
+				}},
+			}},
+		},
 	}}
 
 	for _, tc := range testCases {