Commit 1918e1f
committed
protoc-gen-go: reference publicly imported symbols directly
Consider this case:
File 1 defines M.
File 2 publicly imports file 1.
File 3 imports file 2, and references M.
Each file is in a different Go package: P1, P2, P3.
Should the generated Go code for file 3 reference P1.M, or P2.M?
The two should be equivalent, since file 2 will contain a forwarding
declaration such as "type M = P1.M".
Historically, we've gone with the latter (P2.M). This does make sense:
A generated file only imports the packages of the files that it directly
imports.
However, this does have some mildly surprising effects. If File 3
imports files 2a and 2b, each of which publicly imports file 1, we need
to arbitrarily pick one of P2a.M or P2b.M. (Admittedly an obscure case.)
Simplify the generator a little bit (and, more importantly, make it
consistent with the v2 generator) and change to referencing public
imports directly.1 parent 9a73c7f commit 1918e1f
File tree
2 files changed
+16
-43
lines changed- protoc-gen-go
- generator
- testdata/import_public/importing
2 files changed
+16
-43
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
973 | 973 | | |
974 | 974 | | |
975 | 975 | | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
991 | | - | |
992 | | - | |
993 | | - | |
994 | | - | |
995 | | - | |
996 | | - | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | | - | |
1008 | | - | |
1009 | 976 | | |
1010 | 977 | | |
1011 | 978 | | |
| |||
1689 | 1656 | | |
1690 | 1657 | | |
1691 | 1658 | | |
1692 | | - | |
1693 | | - | |
1694 | | - | |
1695 | | - | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
1696 | 1666 | | |
| 1667 | + | |
| 1668 | + | |
1697 | 1669 | | |
1698 | 1670 | | |
1699 | 1671 | | |
| |||
Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments