Skip to content

Commit d1b311f

Browse files
authored
Merge pull request github#17358 from github/mbg/go/1.23-transparent-aliases
Go: Support 1.23 (Transparent aliases)
2 parents 1e32e84 + 772bc9b commit d1b311f

22 files changed

+120
-9
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ use_repo(
153153
)
154154

155155
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
156-
go_sdk.download(version = "1.22.2")
156+
go_sdk.download(version = "1.23.1")
157157

158158
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
159159
go_deps.from_file(go_mod = "//go/extractor:go.mod")

go/actions/test/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ inputs:
44
go-test-version:
55
description: Which Go version to use for running the tests
66
required: false
7-
default: ~1.22.0
7+
default: "~1.23.1"
88
run-code-checks:
99
description: Whether to run formatting, code and qhelp generation checks
1010
required: false

go/extractor/autobuilder/build-environment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
var minGoVersion = util.NewSemVer("1.11")
15-
var maxGoVersion = util.NewSemVer("1.22")
15+
var maxGoVersion = util.NewSemVer("1.23")
1616

1717
type versionInfo struct {
1818
goModVersion util.SemVer // The version of Go found in the go directive in the `go.mod` file.

go/extractor/extractor.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,9 +1507,24 @@ func extractSpec(tw *trap.Writer, spec ast.Spec, parent trap.Label, idx int) {
15071507
extractNodeLocation(tw, spec, lbl)
15081508
}
15091509

1510+
// Determines whether the given type is an alias.
1511+
func isAlias(tp types.Type) bool {
1512+
_, ok := tp.(*types.Alias)
1513+
return ok
1514+
}
1515+
1516+
// If the given type is a type alias, this function resolves it to its underlying type.
1517+
func resolveTypeAlias(tp types.Type) types.Type {
1518+
if isAlias(tp) {
1519+
return types.Unalias(tp) // tp.Underlying()
1520+
}
1521+
return tp
1522+
}
1523+
15101524
// extractType extracts type information for `tp` and returns its associated label;
15111525
// types are only extracted once, so the second time `extractType` is invoked it simply returns the label
15121526
func extractType(tw *trap.Writer, tp types.Type) trap.Label {
1527+
tp = resolveTypeAlias(tp)
15131528
lbl, exists := getTypeLabel(tw, tp)
15141529
if !exists {
15151530
var kind int
@@ -1666,6 +1681,7 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
16661681
// is constructed from their globally unique ID. This prevents cyclic type keys
16671682
// since type recursion in Go always goes through named types.
16681683
func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
1684+
tp = resolveTypeAlias(tp)
16691685
lbl, exists := tw.Labeler.TypeLabels[tp]
16701686
if !exists {
16711687
switch tp := tp.(type) {

go/extractor/go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/github/codeql-go/extractor
22

3-
go 1.22.0
3+
go 1.23
4+
5+
toolchain go1.23.1
46

57
// when updating this, run
68
// bazel run @rules_go//go -- mod tidy

go/ql/test/extractor-tests/diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| -:0:0:0:0 | package ; expected main |
1+
| -:0:0:0:0 | package ; expected package main |
22
| broken2/test1.go:4:2:4:2 | undefined: fmt |
33
| broken2/test1.go:5:2:5:2 | undefined: fmt |
44
| broken2/test1.go:5:14:5:14 | undefined: a |

go/ql/test/library-tests/semmle/go/Files/CONSISTENCY/UnexpectedFrontendErrors.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| -:0:0:0:0 | package ; expected nonexistent |
1+
| -:0:0:0:0 | package ; expected package nonexistent |
22
| vendor/github.com/github/nonexistent/bad.go:1:57:1:57 | expected ';', found 'EOF' |
33
| vendor/github.com/github/nonexistent/bad.go:1:57:1:57 | expected 'IDENT', found 'EOF' |
44
| vendor/github.com/github/nonexistent/bad.go:1:57:1:57 | expected 'package', found 'EOF' |

go/ql/test/library-tests/semmle/go/Function/TypeParamType.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
| E | Ordered |
22
| E | comparable |
33
| E | interface { } |
4+
| E | interface { ~uint16 \| ~uint32 } |
45
| E1 | interface { } |
56
| E2 | interface { } |
67
| Edge | EdgeConstraint |
78
| Edge | interface { } |
89
| F | floaty |
910
| K | comparable |
11+
| K | interface { } |
12+
| N | interface { int64 \| uint64 } |
1013
| Node | NodeConstraint |
1114
| Node | interface { } |
1215
| S | interface { } |
@@ -15,6 +18,7 @@
1518
| S2 | interface { ~[]E2 } |
1619
| SF2 | interface { } |
1720
| SG2 | interface { } |
21+
| Slice | interface { ~[]E } |
1822
| T | Ordered |
1923
| T | comparable |
2024
| T | interface { string \| []uint8 } |
@@ -27,4 +31,5 @@
2731
| TG2 | interface { } |
2832
| U | interface { } |
2933
| V | interface { int64 \| float64 } |
34+
| V | interface { } |
3035
| bytes | interface { []uint8 \| string } |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
entities
2+
| aliases.go | aliases.go:3:6:3:13 | aliasesX | 1 | file://:0:0:0:0 | int |
3+
| aliases.go | aliases.go:4:6:4:13 | aliasesY | 1 | file://:0:0:0:0 | int |
4+
| aliases.go | aliases.go:6:6:6:14 | aliasesS1 | 1 | file://:0:0:0:0 | struct type |
5+
| aliases.go | aliases.go:6:26:6:26 | x | 3 | file://:0:0:0:0 | int |
6+
| aliases.go | aliases.go:8:6:8:14 | aliasesS2 | 1 | file://:0:0:0:0 | struct type |
7+
| aliases.go | aliases.go:8:26:8:26 | x | 3 | file://:0:0:0:0 | int |
8+
| aliases.go | aliases.go:10:6:10:6 | F | 1 | file://:0:0:0:0 | signature type |
9+
| aliases.go | aliases.go:10:8:10:11 | Afs1 | 1 | file://:0:0:0:0 | struct type |
10+
| aliases.go | aliases.go:14:6:14:6 | G | 1 | file://:0:0:0:0 | signature type |
11+
| aliases.go | aliases.go:14:8:14:11 | Afs2 | 1 | file://:0:0:0:0 | struct type |
12+
| aliases.go | aliases.go:19:6:19:7 | S3 | 1 | aliases.go:19:6:19:7 | S3 |
13+
| aliases.go | aliases.go:19:17:19:17 | x | 3 | file://:0:0:0:0 | int |
14+
| aliases.go | aliases.go:22:6:22:6 | T | 1 | aliases.go:19:6:19:7 | S3 |
15+
| aliases.go | aliases.go:25:6:25:6 | H | 1 | file://:0:0:0:0 | signature type |
16+
| aliases.go | aliases.go:25:8:25:11 | Afs3 | 1 | aliases.go:19:6:19:7 | S3 |
17+
#select
18+
| F | func(struct { x int }) int |
19+
| G | func(struct { x int }) int |
20+
| H | func(S3) int |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import go
2+
3+
int countDecls(Entity e) { result = count(Ident decl | decl = e.getDeclaration()) }
4+
5+
query predicate entities(string fp, Entity e, int c, Type ty) {
6+
c = countDecls(e) and
7+
ty = e.getType() and
8+
exists(DbLocation loc |
9+
loc = e.getDeclaration().getLocation() and
10+
fp = loc.getFile().getBaseName() and
11+
fp = "aliases.go"
12+
)
13+
}
14+
15+
from string fp, FuncDecl decl, SignatureType sig
16+
where
17+
decl.hasLocationInfo(fp, _, _, _, _) and
18+
decl.getName() = ["F", "G", "H"] and
19+
sig = decl.getType() and
20+
fp.matches("%aliases.go%")
21+
select decl.getName(), sig.pp()

0 commit comments

Comments
 (0)