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.go b/reflect/protodesc/protodesc.go
index c1ed334..2bf65eb 100644
--- a/reflect/protodesc/protodesc.go
+++ b/reflect/protodesc/protodesc.go
@@ -112,13 +112,13 @@
 	return prototype.NewFile(&f)
 }
 
-type importSet map[protoreflect.FileDescriptor]bool
+type importSet map[string]bool
 
 func importedFiles(imps []protoreflect.FileImport) importSet {
 	ret := make(importSet)
 	for _, imp := range imps {
-		ret[imp.FileDescriptor] = true
-		addPublicImports(imp.FileDescriptor, ret)
+		ret[imp.Path()] = true
+		addPublicImports(imp, ret)
 	}
 	return ret
 }
@@ -128,8 +128,8 @@
 	for i := 0; i < imps.Len(); i++ {
 		imp := imps.Get(i)
 		if imp.IsPublic {
-			out[imp.FileDescriptor] = true
-			addPublicImports(imp.FileDescriptor, out)
+			out[imp.Path()] = true
+			addPublicImports(imp, out)
 		}
 	}
 }
@@ -381,7 +381,7 @@
 	if fd == nil {
 		return errors.New("%v has no parent FileDescriptor", d.FullName())
 	}
-	if !imps[fd] {
+	if !imps[fd.Path()] {
 		return errors.New("reference to type %v without import of %v", d.FullName(), fd.Path())
 	}
 	return nil