Skip to content

Commit

Permalink
[release-branch.go1.23] cmd/compile/internal/importer: enable aliases
Browse files Browse the repository at this point in the history
Flips the pkgReader.enableAlias flag to true when reading unified IR.
This was disabled while resolving golang#66873. This resolves the TODO to
flip it back to true.

Fixes golang#70394
Fixes golang#70517
Updates golang#66873

Change-Id: Ifd52b0f9510d6bcf151de1c9a18d71ab548c14e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/604099
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
(cherry picked from commit 209ed1a)
Reviewed-on: https://go-review.googlesource.com/c/go/+/631855
Commit-Queue: Tim King <taking@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
  • Loading branch information
timothy-king authored and yangjuncode committed Dec 27, 2024
1 parent 194de8f commit 7d55f04
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/cmd/compile/internal/importer/gcimporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,23 @@ func TestIssue25596(t *testing.T) {
compileAndImportPkg(t, "issue25596")
}

func TestIssue70394(t *testing.T) {
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
}

pkg := compileAndImportPkg(t, "alias")
obj := lookupObj(t, pkg.Scope(), "A")

typ := obj.Type()
if _, ok := typ.(*types2.Alias); !ok {
t.Fatalf("type of %s is %s, wanted an alias", obj, typ)
}
}

func importPkg(t *testing.T, path, srcDir string) *types2.Package {
pkg, err := Import(make(map[string]*types2.Package), path, srcDir, nil)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions src/cmd/compile/internal/importer/testdata/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package testdata

type A = int32
8 changes: 3 additions & 5 deletions src/cmd/compile/internal/importer/ureader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ func ReadPackage(ctxt *types2.Context, imports map[string]*types2.Package, input
pr := pkgReader{
PkgDecoder: input,

ctxt: ctxt,
imports: imports,
// Currently, the compiler panics when using Alias types.
// TODO(gri) set to true once this is fixed (issue #66873)
enableAlias: false,
ctxt: ctxt,
imports: imports,
enableAlias: true,

posBases: make([]*syntax.PosBase, input.NumElems(pkgbits.RelocPosBase)),
pkgs: make([]*types2.Package, input.NumElems(pkgbits.RelocPkg)),
Expand Down

0 comments on commit 7d55f04

Please sign in to comment.