@@ -2645,6 +2645,42 @@ func testTypecheckCgo(t *testing.T, exporter packagestest.Exporter) {
2645
2645
}
2646
2646
}
2647
2647
2648
+ // TestIssue48226 ensures that when NeedSyntax is provided we do not nullify the
2649
+ // Fset, which is needed to resolve the syntax tree element positions to files.
2650
+ func TestIssue48226 (t * testing.T ) { testAllOrModulesParallel (t , testIssue48226 ) }
2651
+ func testIssue48226 (t * testing.T , exporter packagestest.Exporter ) {
2652
+ exported := packagestest .Export (t , exporter , []packagestest.Module {
2653
+ {
2654
+ Name : "golang.org/fake/syntax" ,
2655
+ Files : map [string ]interface {}{
2656
+ "syntax.go" : `package test` ,
2657
+ },
2658
+ },
2659
+ })
2660
+ defer exported .Cleanup ()
2661
+
2662
+ exported .Config .Mode = packages .NeedFiles | packages .NeedSyntax
2663
+
2664
+ initial , err := packages .Load (exported .Config , "golang.org/fake/syntax" )
2665
+ if err != nil {
2666
+ t .Fatal (err )
2667
+ }
2668
+ if len (initial ) != 1 {
2669
+ t .Fatalf ("exepected 1 package, got %d" , len (initial ))
2670
+ }
2671
+ pkg := initial [0 ]
2672
+
2673
+ if len (pkg .Errors ) != 0 {
2674
+ t .Fatalf ("package has errors: %v" , pkg .Errors )
2675
+ }
2676
+
2677
+ fname := pkg .Fset .File (pkg .Syntax [0 ].Pos ()).Name ()
2678
+ if filepath .Base (fname ) != "syntax.go" {
2679
+ t .Errorf ("expected the package declaration position " +
2680
+ "to resolve to \" syntax.go\" , got %q instead" , fname )
2681
+ }
2682
+ }
2683
+
2648
2684
func TestModule (t * testing.T ) {
2649
2685
testAllOrModulesParallel (t , testModule )
2650
2686
}
0 commit comments