From d790d1ff08cda72fa3e8228a7a72ba066bafdd37 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 24 Jul 2024 11:35:26 +0100 Subject: [PATCH 01/12] Go: Use 1.23 in build process --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 6026958de63e..4237c8cb85cf 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -153,7 +153,7 @@ use_repo( ) go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") -go_sdk.download(version = "1.22.2") +go_sdk.download(version = "1.23.0") go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps") go_deps.from_file(go_mod = "//go/extractor:go.mod") From ca796b0383d454e4d4061a35d2d94d514511c706 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 24 Jul 2024 11:19:42 +0100 Subject: [PATCH 02/12] Go: Use 1.23 in tests --- go/actions/test/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/actions/test/action.yml b/go/actions/test/action.yml index cc92ede59b9a..d16cd4832f74 100644 --- a/go/actions/test/action.yml +++ b/go/actions/test/action.yml @@ -4,7 +4,7 @@ inputs: go-test-version: description: Which Go version to use for running the tests required: false - default: ~1.22.0 + default: "~1.23.0" run-code-checks: description: Whether to run formatting, code and qhelp generation checks required: false From 4dead2bd8d3b6c117ae71e81c5305b6b02df2083 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 24 Jul 2024 11:35:01 +0100 Subject: [PATCH 03/12] Go: Use 1.23 for extractor --- go/extractor/go.mod | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/go/extractor/go.mod b/go/extractor/go.mod index 42366f172863..7d78ce08e67d 100644 --- a/go/extractor/go.mod +++ b/go/extractor/go.mod @@ -1,6 +1,8 @@ module github.com/github/codeql-go/extractor -go 1.22.0 +go 1.23 + +toolchain go1.23.0 // when updating this, run // bazel run @rules_go//go -- mod tidy From c8e732468a6e0136f5a298bb1968983f1debc87b Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 24 Jul 2024 11:49:55 +0100 Subject: [PATCH 04/12] Go: Update frontend error messages for Go 1.23 --- .../diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected | 2 +- .../go/Files/CONSISTENCY/UnexpectedFrontendErrors.expected | 2 +- .../Diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected | 2 +- go/ql/test/query-tests/Diagnostics/ExtractionErrors.expected | 2 +- .../Summary/CONSISTENCY/UnexpectedFrontendErrors.expected | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go/ql/test/extractor-tests/diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected b/go/ql/test/extractor-tests/diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected index aa526b3e7505..abe30bd00880 100644 --- a/go/ql/test/extractor-tests/diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected +++ b/go/ql/test/extractor-tests/diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected @@ -1,4 +1,4 @@ -| -:0:0:0:0 | package ; expected main | +| -:0:0:0:0 | package ; expected package main | | broken2/test1.go:4:2:4:2 | undefined: fmt | | broken2/test1.go:5:2:5:2 | undefined: fmt | | broken2/test1.go:5:14:5:14 | undefined: a | diff --git a/go/ql/test/library-tests/semmle/go/Files/CONSISTENCY/UnexpectedFrontendErrors.expected b/go/ql/test/library-tests/semmle/go/Files/CONSISTENCY/UnexpectedFrontendErrors.expected index 6a47139fb8dd..e63bda23e944 100644 --- a/go/ql/test/library-tests/semmle/go/Files/CONSISTENCY/UnexpectedFrontendErrors.expected +++ b/go/ql/test/library-tests/semmle/go/Files/CONSISTENCY/UnexpectedFrontendErrors.expected @@ -1,4 +1,4 @@ -| -:0:0:0:0 | package ; expected nonexistent | +| -:0:0:0:0 | package ; expected package nonexistent | | vendor/github.com/github/nonexistent/bad.go:1:57:1:57 | expected ';', found 'EOF' | | vendor/github.com/github/nonexistent/bad.go:1:57:1:57 | expected 'IDENT', found 'EOF' | | vendor/github.com/github/nonexistent/bad.go:1:57:1:57 | expected 'package', found 'EOF' | diff --git a/go/ql/test/query-tests/Diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected b/go/ql/test/query-tests/Diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected index 909c0a71eded..19c2ad21db8c 100644 --- a/go/ql/test/query-tests/Diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected +++ b/go/ql/test/query-tests/Diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected @@ -1,5 +1,5 @@ | -:0:0:0:0 | malformed import path "github.com/github/codeql-go/ql/test/query-tests/Diagnostics/invalid{": invalid char '{' | -| -:0:0:0:0 | package ; expected main | +| -:0:0:0:0 | package ; expected package main | | bad.go:3:1:3:1 | expected 'package', found avvu | | bad.go:3:1:3:1 | expected 'package', found avvu | | bad.go:3:5:3:5 | expected 'IDENT', found newline | diff --git a/go/ql/test/query-tests/Diagnostics/ExtractionErrors.expected b/go/ql/test/query-tests/Diagnostics/ExtractionErrors.expected index c7695f79dcab..b3a9e8631f08 100644 --- a/go/ql/test/query-tests/Diagnostics/ExtractionErrors.expected +++ b/go/ql/test/query-tests/Diagnostics/ExtractionErrors.expected @@ -4,4 +4,4 @@ | Extraction failed with error expected 'IDENT', found newline | 2 | | Extraction failed with error expected 'package', found avvu | 2 | | Extraction failed with error malformed import path "github.com/github/codeql-go/ql/test/query-tests/Diagnostics/invalid{": invalid char '{' | 2 | -| Extraction failed with error package ; expected main | 2 | +| Extraction failed with error package ; expected package main | 2 | diff --git a/go/ql/test/query-tests/Summary/CONSISTENCY/UnexpectedFrontendErrors.expected b/go/ql/test/query-tests/Summary/CONSISTENCY/UnexpectedFrontendErrors.expected index d4dff7b992f5..b0969d1a2244 100644 --- a/go/ql/test/query-tests/Summary/CONSISTENCY/UnexpectedFrontendErrors.expected +++ b/go/ql/test/query-tests/Summary/CONSISTENCY/UnexpectedFrontendErrors.expected @@ -1,4 +1,4 @@ -| -:0:0:0:0 | package ; expected main | +| -:0:0:0:0 | package ; expected package main | | empty-file.go:1:1:1:1 | expected ';', found 'EOF' | | empty-file.go:1:1:1:1 | expected 'IDENT', found 'EOF' | | empty-file.go:1:1:1:1 | expected 'package', found 'EOF' | From c5b8163493e68fcfed870d12b5986614ce3022e0 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 2 Sep 2024 16:56:17 +0100 Subject: [PATCH 05/12] Go: Handle `Alias` types by extracting the underlying types --- go/extractor/extractor.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/go/extractor/extractor.go b/go/extractor/extractor.go index df3a43f80cfa..08e3282588ee 100644 --- a/go/extractor/extractor.go +++ b/go/extractor/extractor.go @@ -1507,9 +1507,18 @@ func extractSpec(tw *trap.Writer, spec ast.Spec, parent trap.Label, idx int) { extractNodeLocation(tw, spec, lbl) } +// If the given type is a type alias, this function resolves it to its underlying type. +func resolveTypeAlias(tp types.Type) types.Type { + if _, ok := tp.(*types.Alias); ok { + return tp.Underlying() + } + return tp +} + // extractType extracts type information for `tp` and returns its associated label; // types are only extracted once, so the second time `extractType` is invoked it simply returns the label func extractType(tw *trap.Writer, tp types.Type) trap.Label { + tp = resolveTypeAlias(tp) lbl, exists := getTypeLabel(tw, tp) if !exists { var kind int @@ -1666,6 +1675,7 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label { // is constructed from their globally unique ID. This prevents cyclic type keys // since type recursion in Go always goes through named types. func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) { + tp = resolveTypeAlias(tp) lbl, exists := tw.Labeler.TypeLabels[tp] if !exists { switch tp := tp.(type) { From 97c3efccd122471a026fd8047ea4086a34ef106d Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Tue, 3 Sep 2024 15:09:15 +0100 Subject: [PATCH 06/12] Go: Factor out `isAlias` function --- go/extractor/extractor.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/go/extractor/extractor.go b/go/extractor/extractor.go index 08e3282588ee..a9b5a6b1d0f0 100644 --- a/go/extractor/extractor.go +++ b/go/extractor/extractor.go @@ -1507,9 +1507,15 @@ func extractSpec(tw *trap.Writer, spec ast.Spec, parent trap.Label, idx int) { extractNodeLocation(tw, spec, lbl) } +// Determines whether the given type is an alias. +func isAlias(tp types.Type) bool { + _, ok := tp.(*types.Alias) + return ok +} + // If the given type is a type alias, this function resolves it to its underlying type. func resolveTypeAlias(tp types.Type) types.Type { - if _, ok := tp.(*types.Alias); ok { + if isAlias(tp) { return tp.Underlying() } return tp From 1a9608a1f5a7d4b0fea233f0bffb0721b765dda9 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Tue, 3 Sep 2024 15:20:08 +0100 Subject: [PATCH 07/12] Go: Don't extract objects for type aliases --- go/extractor/extractor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/extractor/extractor.go b/go/extractor/extractor.go index a9b5a6b1d0f0..343eb3c35bb4 100644 --- a/go/extractor/extractor.go +++ b/go/extractor/extractor.go @@ -1516,7 +1516,7 @@ func isAlias(tp types.Type) bool { // If the given type is a type alias, this function resolves it to its underlying type. func resolveTypeAlias(tp types.Type) types.Type { if isAlias(tp) { - return tp.Underlying() + return types.Unalias(tp) // tp.Underlying() } return tp } From 8380d71b0111526e1a6dd4d449a4034ea2b7ebe3 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Fri, 16 Aug 2024 11:44:14 +0100 Subject: [PATCH 08/12] Go: Add test for `AliasType` extraction --- .../semmle/go/Types/Aliases.expected | 20 ++++++++++++++ .../library-tests/semmle/go/Types/Aliases.ql | 23 ++++++++++++++++ .../semmle/go/Types/Field_getPackage.expected | 3 +++ .../go/Types/Field_hasQualifiedName2.expected | 3 +++ .../go/Types/Field_hasQualifiedName3.expected | 3 +++ .../semmle/go/Types/QualifiedNames.expected | 1 + .../SignatureType_getNumParameter.expected | 3 +++ .../Types/SignatureType_getNumResult.expected | 3 +++ .../semmle/go/Types/StructFields.expected | 3 +++ .../semmle/go/Types/Types.expected | 1 + .../library-tests/semmle/go/Types/aliases.go | 27 +++++++++++++++++++ 11 files changed, 90 insertions(+) create mode 100644 go/ql/test/library-tests/semmle/go/Types/Aliases.expected create mode 100644 go/ql/test/library-tests/semmle/go/Types/Aliases.ql create mode 100644 go/ql/test/library-tests/semmle/go/Types/aliases.go diff --git a/go/ql/test/library-tests/semmle/go/Types/Aliases.expected b/go/ql/test/library-tests/semmle/go/Types/Aliases.expected new file mode 100644 index 000000000000..2c09dd790a56 --- /dev/null +++ b/go/ql/test/library-tests/semmle/go/Types/Aliases.expected @@ -0,0 +1,20 @@ +entities +| aliases.go | aliases.go:3:6:3:13 | aliasesX | 1 | file://:0:0:0:0 | int | +| aliases.go | aliases.go:4:6:4:13 | aliasesY | 1 | file://:0:0:0:0 | int | +| aliases.go | aliases.go:6:6:6:14 | aliasesS1 | 1 | file://:0:0:0:0 | struct type | +| aliases.go | aliases.go:6:26:6:26 | x | 3 | file://:0:0:0:0 | int | +| aliases.go | aliases.go:8:6:8:14 | aliasesS2 | 1 | file://:0:0:0:0 | struct type | +| aliases.go | aliases.go:8:26:8:26 | x | 3 | file://:0:0:0:0 | int | +| aliases.go | aliases.go:10:6:10:6 | F | 1 | file://:0:0:0:0 | signature type | +| aliases.go | aliases.go:10:8:10:11 | Afs1 | 1 | file://:0:0:0:0 | struct type | +| aliases.go | aliases.go:14:6:14:6 | G | 1 | file://:0:0:0:0 | signature type | +| aliases.go | aliases.go:14:8:14:11 | Afs2 | 1 | file://:0:0:0:0 | struct type | +| aliases.go | aliases.go:19:6:19:7 | S3 | 1 | aliases.go:19:6:19:7 | S3 | +| aliases.go | aliases.go:19:17:19:17 | x | 3 | file://:0:0:0:0 | int | +| aliases.go | aliases.go:22:6:22:6 | T | 1 | aliases.go:19:6:19:7 | S3 | +| aliases.go | aliases.go:25:6:25:6 | H | 1 | file://:0:0:0:0 | signature type | +| aliases.go | aliases.go:25:8:25:11 | Afs3 | 1 | aliases.go:19:6:19:7 | S3 | +#select +| F | func(struct { x int }) int | +| G | func(struct { x int }) int | +| H | func(S3) int | diff --git a/go/ql/test/library-tests/semmle/go/Types/Aliases.ql b/go/ql/test/library-tests/semmle/go/Types/Aliases.ql new file mode 100644 index 000000000000..8e234e7a381e --- /dev/null +++ b/go/ql/test/library-tests/semmle/go/Types/Aliases.ql @@ -0,0 +1,23 @@ +import go + +int countDecls(Entity e) { + result = count(Ident decl | decl = e.getDeclaration()) +} + +query predicate entities(string fp, Entity e, int c, Type ty) { + c = countDecls(e) and + ty = e.getType() and + exists(DbLocation loc | + loc = e.getDeclaration().getLocation() and + fp = loc.getFile().getBaseName() and + fp = "aliases.go" + ) +} + +from string fp, FuncDecl decl, SignatureType sig +where + decl.hasLocationInfo(fp, _, _, _, _) and + decl.getName() = ["F", "G", "H"] and + sig = decl.getType() and + fp.matches("%aliases.go%") +select decl.getName(), sig.pp() diff --git a/go/ql/test/library-tests/semmle/go/Types/Field_getPackage.expected b/go/ql/test/library-tests/semmle/go/Types/Field_getPackage.expected index e635a046b23a..758199c63523 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Field_getPackage.expected +++ b/go/ql/test/library-tests/semmle/go/Types/Field_getPackage.expected @@ -1,3 +1,6 @@ +| aliases.go:6:26:6:26 | x | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | +| aliases.go:8:26:8:26 | x | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | +| aliases.go:19:17:19:17 | x | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | | cyclic.go:4:3:4:3 | s | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | | cyclic.go:8:3:8:3 | u | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | | cyclic.go:9:2:9:2 | f | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | diff --git a/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName2.expected b/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName2.expected index 2ac146f266aa..4c69f36880be 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName2.expected +++ b/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName2.expected @@ -1,3 +1,6 @@ +| aliases.go:6:26:6:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 | x | +| aliases.go:8:26:8:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 | x | +| aliases.go:19:17:19:17 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 | x | | cyclic.go:4:3:4:3 | s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.s | s | | cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.t | u | | cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.u | u | diff --git a/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName3.expected b/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName3.expected index acdddfe867ea..4fe8aee19f4c 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName3.expected +++ b/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName3.expected @@ -1,3 +1,6 @@ +| aliases.go:6:26:6:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | S3 | x | +| aliases.go:8:26:8:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | S3 | x | +| aliases.go:19:17:19:17 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | S3 | x | | cyclic.go:4:3:4:3 | s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | s | s | | cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | t | u | | cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | u | u | diff --git a/go/ql/test/library-tests/semmle/go/Types/QualifiedNames.expected b/go/ql/test/library-tests/semmle/go/Types/QualifiedNames.expected index 3f170370284c..bedfbc5fa00a 100644 --- a/go/ql/test/library-tests/semmle/go/Types/QualifiedNames.expected +++ b/go/ql/test/library-tests/semmle/go/Types/QualifiedNames.expected @@ -1,3 +1,4 @@ +| aliases.go:19:6:19:7 | S3 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 | | cyclic.go:3:6:3:6 | s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.s | | cyclic.go:7:6:7:6 | t | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.t | | cyclic.go:12:6:12:6 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.u | diff --git a/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumParameter.expected b/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumParameter.expected index 843020b9a955..6742adf837fd 100644 --- a/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumParameter.expected +++ b/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumParameter.expected @@ -1,3 +1,6 @@ +| aliases.go:10:1:12:1 | function declaration | 1 | +| aliases.go:14:1:16:1 | function declaration | 1 | +| aliases.go:25:1:27:1 | function declaration | 1 | | depth.go:22:1:25:1 | function declaration | 0 | | generic.go:70:1:72:1 | function declaration | 1 | | generic.go:74:1:80:1 | function declaration | 1 | diff --git a/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumResult.expected b/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumResult.expected index 9072be74806c..c6b20f548306 100644 --- a/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumResult.expected +++ b/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumResult.expected @@ -1,3 +1,6 @@ +| aliases.go:10:1:12:1 | function declaration | 1 | +| aliases.go:14:1:16:1 | function declaration | 1 | +| aliases.go:25:1:27:1 | function declaration | 1 | | depth.go:22:1:25:1 | function declaration | 0 | | generic.go:70:1:72:1 | function declaration | 1 | | generic.go:74:1:80:1 | function declaration | 0 | diff --git a/go/ql/test/library-tests/semmle/go/Types/StructFields.expected b/go/ql/test/library-tests/semmle/go/Types/StructFields.expected index 1db8f36d2511..5bce8e1d7df1 100644 --- a/go/ql/test/library-tests/semmle/go/Types/StructFields.expected +++ b/go/ql/test/library-tests/semmle/go/Types/StructFields.expected @@ -1,3 +1,6 @@ +| aliases.go:19:6:19:7 | S3 | aliases.go:6:18:6:37 | struct type | x | int | +| aliases.go:19:6:19:7 | S3 | aliases.go:8:18:8:37 | struct type | x | int | +| aliases.go:19:6:19:7 | S3 | aliases.go:19:9:19:23 | struct type | x | int | | cyclic.go:3:6:3:6 | s | cyclic.go:3:8:5:1 | struct type | s | * s | | cyclic.go:7:6:7:6 | t | cyclic.go:7:8:10:1 | struct type | f | int | | cyclic.go:7:6:7:6 | t | cyclic.go:7:8:10:1 | struct type | t | t | diff --git a/go/ql/test/library-tests/semmle/go/Types/Types.expected b/go/ql/test/library-tests/semmle/go/Types/Types.expected index b4a05a8858d1..3801769db02d 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Types.expected +++ b/go/ql/test/library-tests/semmle/go/Types/Types.expected @@ -1,3 +1,4 @@ +| aliases.go:19:6:19:7 | S3 | S3 | | cyclic.go:3:6:3:6 | s | s | | cyclic.go:7:6:7:6 | t | t | | cyclic.go:12:6:12:6 | u | u | diff --git a/go/ql/test/library-tests/semmle/go/Types/aliases.go b/go/ql/test/library-tests/semmle/go/Types/aliases.go new file mode 100644 index 000000000000..49f846587328 --- /dev/null +++ b/go/ql/test/library-tests/semmle/go/Types/aliases.go @@ -0,0 +1,27 @@ +package main + +type aliasesX = int +type aliasesY = int + +type aliasesS1 = struct{ x aliasesX } + +type aliasesS2 = struct{ x aliasesY } + +func F(Afs1 aliasesS1) int { + return G(Afs1) + Afs1.x +} + +func G(Afs2 aliasesS2) int { + return Afs2.x +} + +// This is a named type, not an alias +type S3 struct{ x int } + +// This is a type alias +type T = S3 + +// We expect `Afs3` to be of type `S3` here, not `struct{ x int }` +func H(Afs3 T) int { + return Afs3.x +} From 195f37267e318da8c8287cda281bd99930023aff Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 4 Sep 2024 11:57:56 +0100 Subject: [PATCH 09/12] Go: Accept new test results --- .../library-tests/semmle/go/Function/TypeParamType.expected | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/go/ql/test/library-tests/semmle/go/Function/TypeParamType.expected b/go/ql/test/library-tests/semmle/go/Function/TypeParamType.expected index bb614a4b41c5..a84d1bd90156 100644 --- a/go/ql/test/library-tests/semmle/go/Function/TypeParamType.expected +++ b/go/ql/test/library-tests/semmle/go/Function/TypeParamType.expected @@ -1,12 +1,15 @@ | E | Ordered | | E | comparable | | E | interface { } | +| E | interface { ~uint16 \| ~uint32 } | | E1 | interface { } | | E2 | interface { } | | Edge | EdgeConstraint | | Edge | interface { } | | F | floaty | | K | comparable | +| K | interface { } | +| N | interface { int64 \| uint64 } | | Node | NodeConstraint | | Node | interface { } | | S | interface { } | @@ -15,6 +18,7 @@ | S2 | interface { ~[]E2 } | | SF2 | interface { } | | SG2 | interface { } | +| Slice | interface { ~[]E } | | T | Ordered | | T | comparable | | T | interface { string \| []uint8 } | @@ -27,4 +31,5 @@ | TG2 | interface { } | | U | interface { } | | V | interface { int64 \| float64 } | +| V | interface { } | | bytes | interface { []uint8 \| string } | From 6ef5063ff03a28a20bc554040b06caa5a3498b85 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 4 Sep 2024 12:03:02 +0100 Subject: [PATCH 10/12] Go: Format `Aliases.ql` --- go/ql/test/library-tests/semmle/go/Types/Aliases.ql | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/go/ql/test/library-tests/semmle/go/Types/Aliases.ql b/go/ql/test/library-tests/semmle/go/Types/Aliases.ql index 8e234e7a381e..79f366e37d94 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Aliases.ql +++ b/go/ql/test/library-tests/semmle/go/Types/Aliases.ql @@ -1,8 +1,6 @@ import go -int countDecls(Entity e) { - result = count(Ident decl | decl = e.getDeclaration()) -} +int countDecls(Entity e) { result = count(Ident decl | decl = e.getDeclaration()) } query predicate entities(string fp, Entity e, int c, Type ty) { c = countDecls(e) and From 9aeaae6068d67126cbdae1cb2eb5260d5042f743 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 4 Sep 2024 14:08:13 +0100 Subject: [PATCH 11/12] Go: Bump `maxGoVersion` to `1.23` --- go/extractor/autobuilder/build-environment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/extractor/autobuilder/build-environment.go b/go/extractor/autobuilder/build-environment.go index 4659fef71dfb..cc3dc62c02dc 100644 --- a/go/extractor/autobuilder/build-environment.go +++ b/go/extractor/autobuilder/build-environment.go @@ -12,7 +12,7 @@ import ( ) var minGoVersion = util.NewSemVer("1.11") -var maxGoVersion = util.NewSemVer("1.22") +var maxGoVersion = util.NewSemVer("1.23") type versionInfo struct { goModVersion util.SemVer // The version of Go found in the go directive in the `go.mod` file. From 772bc9b5c864f77d2a2814af02b18b53c4505aa0 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Thu, 5 Sep 2024 21:12:09 +0100 Subject: [PATCH 12/12] Go: Bump everything to 1.23.1 --- MODULE.bazel | 2 +- go/actions/test/action.yml | 2 +- go/extractor/go.mod | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 4237c8cb85cf..4db30803a3c8 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -153,7 +153,7 @@ use_repo( ) go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") -go_sdk.download(version = "1.23.0") +go_sdk.download(version = "1.23.1") go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps") go_deps.from_file(go_mod = "//go/extractor:go.mod") diff --git a/go/actions/test/action.yml b/go/actions/test/action.yml index d16cd4832f74..5228f440971e 100644 --- a/go/actions/test/action.yml +++ b/go/actions/test/action.yml @@ -4,7 +4,7 @@ inputs: go-test-version: description: Which Go version to use for running the tests required: false - default: "~1.23.0" + default: "~1.23.1" run-code-checks: description: Whether to run formatting, code and qhelp generation checks required: false diff --git a/go/extractor/go.mod b/go/extractor/go.mod index 7d78ce08e67d..7b294e5b74ff 100644 --- a/go/extractor/go.mod +++ b/go/extractor/go.mod @@ -2,7 +2,7 @@ module github.com/github/codeql-go/extractor go 1.23 -toolchain go1.23.0 +toolchain go1.23.1 // when updating this, run // bazel run @rules_go//go -- mod tidy