Skip to content

Commit 60e7b15

Browse files
authored
Merge branch 'aws:main' into refactor/fix_deprecated_for_ioutil
2 parents e06da44 + a7d0f1e commit 60e7b15

File tree

7 files changed

+97
-17
lines changed

7 files changed

+97
-17
lines changed

CONTRIBUTING.md

+31
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,37 @@ To send us a pull request, please:
3939
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
4040
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
4141

42+
### Changelog Documents
43+
44+
(You can SKIP this step if you are only changing the code generator, and not the runtime).
45+
46+
When submitting a pull request please include a changelog file on a folder named `.changelog`.
47+
These are used to generate the content `CHANGELOG.md` and Release Notes. The format of the file is as follows:
48+
49+
```
50+
{
51+
"id": "12345678-1234-1234-1234-123456789012"
52+
"type": "bugfix"
53+
"collapse": true
54+
"description": "Fix improper use of printf-style functions.",
55+
"modules": [
56+
"."
57+
]
58+
}
59+
```
60+
61+
* id: a UUID. This should also be used for the name of the file, so if your id is `12345678-1234-1234-1234-123456789012` the file should be named `12345678-1234-1234-1234-123456789012.json/`
62+
* type: one of the following:
63+
* bugfix: Fixing an existing bug
64+
* Feature: Adding a new feature to an existing service
65+
* Release: Releasing a new module
66+
* Dependency: Updating dependencies
67+
* Announcement: Making an announcement, like deprecation of a module
68+
* collapse: whether this change should appear separately on the release notes on every module listed on `modules` (`"collapse": false`), or if it should show up as a single entry (`"collapse": true`)
69+
* For the smithy-go repository this should always be `false`
70+
* description: Description of this change. Most of the times is the same as the title of the PR
71+
* modules: which Go modules does this change impact. The root module is expressed as "."
72+
4273

4374
## Finding contributions to work on
4475
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,12 @@ module-version:
9898
##############
9999
.PHONY: install-changelog
100100

101+
external-changelog:
102+
mkdir -p .changelog
103+
cp changelog-template.json .changelog/00000000-0000-0000-0000-000000000000.json
104+
@echo "Generate a new UUID and update the file at .changelog/00000000-0000-0000-0000-000000000000.json"
105+
@echo "Make sure to rename the file with your new id, like .changelog/12345678-1234-1234-1234-123456789012.json"
106+
@echo "See CONTRIBUTING.md 'Changelog Documents' and an example at https://github.com/aws/smithy-go/pull/543/files"
107+
101108
install-changelog:
102109
go install ${REPOTOOLS_MODULE}/cmd/changelog@${REPOTOOLS_VERSION}

changelog-template.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "00000000-0000-0000-0000-000000000000",
3+
"type": "feature|bugfix|dependency",
4+
"description": "Description of your changes",
5+
"collapse": false,
6+
"modules": [
7+
"."
8+
]
9+
}

codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoJmespathExpressionGenerator.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.smithy.go.codegen;
1717

1818
import static software.amazon.smithy.go.codegen.GoWriter.goTemplate;
19+
import static software.amazon.smithy.go.codegen.SymbolUtils.isNilable;
1920
import static software.amazon.smithy.go.codegen.SymbolUtils.isPointable;
2021
import static software.amazon.smithy.go.codegen.SymbolUtils.sliceOf;
2122
import static software.amazon.smithy.go.codegen.util.ShapeUtil.BOOL_SHAPE;
@@ -280,7 +281,21 @@ private Variable visitProjection(ProjectionExpression expr, Variable current) {
280281

281282
private Variable visitSub(Subexpression expr, Variable current) {
282283
var left = visit(expr.getLeft(), current);
283-
return visit(expr.getRight(), left);
284+
if (!isNilable(left.type)) {
285+
return visit(expr.getRight(), left);
286+
}
287+
288+
var lookahead = new GoJmespathExpressionGenerator(ctx, new GoWriter(""))
289+
.generate(expr.getRight(), left);
290+
var ident = nextIdent();
291+
writer.write("var $L $P", ident, lookahead.type);
292+
writer.write("if $L != nil {", left.ident);
293+
writer.indent();
294+
var inner = visit(expr.getRight(), left);
295+
writer.write("$L = $L", ident, inner.ident);
296+
writer.dedent();
297+
writer.write("}");
298+
return new Variable(inner.shape, ident, inner.type);
284299
}
285300

286301
private Variable visitField(FieldExpression expr, Variable current) {

codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/Waiters.java

+1
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ private void generateRetryable(
670670
});
671671

672672
writer.write("");
673+
writer.write("if err != nil { return false, err }");
673674
writer.write("return true, nil");
674675
});
675676
}

codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/Waiters2.java

+1
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ private void generateRetryable(
649649
});
650650

651651
writer.write("");
652+
writer.write("if err != nil { return false, err }");
652653
writer.write("return true, nil");
653654
});
654655
}

codegen/smithy-go-codegen/src/test/java/software/amazon/smithy/go/codegen/GoJmespathExpressionGeneratorTest.java

+32-16
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ public void testSubexpression() {
124124
assertThat(actual.ident(), Matchers.equalTo("v2"));
125125
assertThat(writer.toString(), Matchers.containsString("""
126126
v1 := input.Nested
127-
v2 := v1.NestedField
127+
var v2 *string
128+
if v1 != nil {
129+
v3 := v1.NestedField
130+
v2 = v3
131+
}
128132
"""));
129133
}
130134

@@ -304,14 +308,18 @@ public void testComparatorStringLHSNil() {
304308
"input"
305309
));
306310
assertThat(actual.shape(), Matchers.equalTo(ShapeUtil.BOOL_SHAPE));
307-
assertThat(actual.ident(), Matchers.equalTo("v4"));
311+
assertThat(actual.ident(), Matchers.equalTo("v5"));
308312
assertThat(writer.toString(), Matchers.containsString("""
309313
v1 := input.Nested
310-
v2 := v1.NestedField
311-
v3 := "foo"
312-
var v4 bool
314+
var v2 *string
315+
if v1 != nil {
316+
v3 := v1.NestedField
317+
v2 = v3
318+
}
319+
v4 := "foo"
320+
var v5 bool
313321
if v2 != nil {
314-
v4 = string(*v2) == string(v3)
322+
v5 = string(*v2) == string(v4)
315323
}
316324
"""));
317325
}
@@ -327,14 +335,18 @@ public void testComparatorStringRHSNil() {
327335
"input"
328336
));
329337
assertThat(actual.shape(), Matchers.equalTo(ShapeUtil.BOOL_SHAPE));
330-
assertThat(actual.ident(), Matchers.equalTo("v4"));
338+
assertThat(actual.ident(), Matchers.equalTo("v5"));
331339
assertThat(writer.toString(), Matchers.containsString("""
332340
v1 := "foo"
333341
v2 := input.Nested
334-
v3 := v2.NestedField
335-
var v4 bool
342+
var v3 *string
343+
if v2 != nil {
344+
v4 := v2.NestedField
345+
v3 = v4
346+
}
347+
var v5 bool
336348
if v3 != nil {
337-
v4 = string(v1) == string(*v3)
349+
v5 = string(v1) == string(*v3)
338350
}
339351
"""));
340352
}
@@ -350,14 +362,18 @@ public void testComparatorStringBothNil() {
350362
"input"
351363
));
352364
assertThat(actual.shape(), Matchers.equalTo(ShapeUtil.BOOL_SHAPE));
353-
assertThat(actual.ident(), Matchers.equalTo("v4"));
365+
assertThat(actual.ident(), Matchers.equalTo("v5"));
354366
assertThat(writer.toString(), Matchers.containsString("""
355367
v1 := input.Nested
356-
v2 := v1.NestedField
357-
v3 := input.SimpleShape
358-
var v4 bool
359-
if v2 != nil && v3 != nil {
360-
v4 = string(*v2) == string(*v3)
368+
var v2 *string
369+
if v1 != nil {
370+
v3 := v1.NestedField
371+
v2 = v3
372+
}
373+
v4 := input.SimpleShape
374+
var v5 bool
375+
if v2 != nil && v4 != nil {
376+
v5 = string(*v2) == string(*v4)
361377
}
362378
"""));
363379
}

0 commit comments

Comments
 (0)