Skip to content

Commit

Permalink
Fix name resolution with fully-qualified names
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhickman committed Sep 1, 2023
1 parent 8697d55 commit 38a8545
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 1 deletion.
2 changes: 1 addition & 1 deletion prost-reflect/src/descriptor/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn resolve_name<'a, 'b>(
Some(full_name) => match names.get(full_name) {
Some(def) => {
if dependencies.contains(&def.file) {
Ok((Cow::Borrowed(full_name), def))
Ok((Cow::Borrowed(name), def))
} else {
Err(vec![(full_name.to_owned(), def.file)])
}
Expand Down
131 changes: 131 additions & 0 deletions prost-reflect/tests/data/name_resolution3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
file:
- name: include/package.proto
package: foo
messageType:
- name: Foo
syntax: proto3
- name: include/no_package.proto
messageType:
- name: Bar
syntax: proto3
- name: name_resolution.proto
package: foo.bar
dependency:
- include/package.proto
- include/no_package.proto
messageType:
- name: FooBar
- name: Names
field:
- name: field1
number: 1
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: ".foo.bar.FooBar"
jsonName: field1
- name: field2
number: 2
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "foo.bar.FooBar"
jsonName: field2
- name: field3
number: 3
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "bar.FooBar"
jsonName: field3
- name: field4
number: 4
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "FooBar"
jsonName: field4
- name: field5
number: 5
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: ".foo.Foo"
jsonName: field5
- name: field6
number: 6
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "foo.Foo"
jsonName: field6
- name: field7
number: 7
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "Foo"
jsonName: field7
- name: field8
number: 8
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: ".Bar"
jsonName: field8
- name: field9
number: 9
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "Bar"
jsonName: field9
nestedType:
- name: Nested
field:
- name: field1
number: 1
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: ".foo.bar.FooBar"
jsonName: field1
- name: field2
number: 2
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "foo.bar.FooBar"
jsonName: field2
- name: field3
number: 3
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "bar.FooBar"
jsonName: field3
- name: field4
number: 4
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "FooBar"
jsonName: field4
- name: field5
number: 5
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: ".foo.Foo"
jsonName: field5
- name: field6
number: 6
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "foo.Foo"
jsonName: field6
- name: field7
number: 7
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "Foo"
jsonName: field7
- name: field8
number: 8
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: ".Bar"
jsonName: field8
- name: field9
number: 9
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
typeName: "Bar"
jsonName: field9
syntax: proto3
1 change: 1 addition & 0 deletions prost-reflect/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ check_err!(invalid_service_type2);
check_err!(invalid_service_type3);
check_err!(name_resolution1);
check_err!(name_resolution2);
check_ok!(name_resolution3);
check_err!(name_collision1);
check_err!(name_collision2);
check_err!(name_collision3);
Expand Down
136 changes: 136 additions & 0 deletions prost-reflect/tests/snapshots/main__name_resolution3.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
source: prost-reflect/tests/main.rs
expression: actual
---
file:
- messageType:
- name: Foo
name: include/package.proto
package: foo
syntax: proto3
- messageType:
- name: Bar
name: include/no_package.proto
syntax: proto3
- dependency:
- include/package.proto
- include/no_package.proto
messageType:
- name: FooBar
- field:
- jsonName: field1
label: LABEL_OPTIONAL
name: field1
number: 1
type: TYPE_MESSAGE
typeName: ".foo.bar.FooBar"
- jsonName: field2
label: LABEL_OPTIONAL
name: field2
number: 2
type: TYPE_MESSAGE
typeName: ".foo.bar.FooBar"
- jsonName: field3
label: LABEL_OPTIONAL
name: field3
number: 3
type: TYPE_MESSAGE
typeName: ".foo.bar.FooBar"
- jsonName: field4
label: LABEL_OPTIONAL
name: field4
number: 4
type: TYPE_MESSAGE
typeName: ".foo.bar.FooBar"
- jsonName: field5
label: LABEL_OPTIONAL
name: field5
number: 5
type: TYPE_MESSAGE
typeName: ".foo.Foo"
- jsonName: field6
label: LABEL_OPTIONAL
name: field6
number: 6
type: TYPE_MESSAGE
typeName: ".foo.Foo"
- jsonName: field7
label: LABEL_OPTIONAL
name: field7
number: 7
type: TYPE_MESSAGE
typeName: ".foo.Foo"
- jsonName: field8
label: LABEL_OPTIONAL
name: field8
number: 8
type: TYPE_MESSAGE
typeName: ".Bar"
- jsonName: field9
label: LABEL_OPTIONAL
name: field9
number: 9
type: TYPE_MESSAGE
typeName: ".Bar"
name: Names
nestedType:
- field:
- jsonName: field1
label: LABEL_OPTIONAL
name: field1
number: 1
type: TYPE_MESSAGE
typeName: ".foo.bar.FooBar"
- jsonName: field2
label: LABEL_OPTIONAL
name: field2
number: 2
type: TYPE_MESSAGE
typeName: ".foo.bar.FooBar"
- jsonName: field3
label: LABEL_OPTIONAL
name: field3
number: 3
type: TYPE_MESSAGE
typeName: ".foo.bar.FooBar"
- jsonName: field4
label: LABEL_OPTIONAL
name: field4
number: 4
type: TYPE_MESSAGE
typeName: ".foo.bar.FooBar"
- jsonName: field5
label: LABEL_OPTIONAL
name: field5
number: 5
type: TYPE_MESSAGE
typeName: ".foo.Foo"
- jsonName: field6
label: LABEL_OPTIONAL
name: field6
number: 6
type: TYPE_MESSAGE
typeName: ".foo.Foo"
- jsonName: field7
label: LABEL_OPTIONAL
name: field7
number: 7
type: TYPE_MESSAGE
typeName: ".foo.Foo"
- jsonName: field8
label: LABEL_OPTIONAL
name: field8
number: 8
type: TYPE_MESSAGE
typeName: ".Bar"
- jsonName: field9
label: LABEL_OPTIONAL
name: field9
number: 9
type: TYPE_MESSAGE
typeName: ".Bar"
name: Nested
name: name_resolution.proto
package: foo.bar
syntax: proto3

0 comments on commit 38a8545

Please sign in to comment.