Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accept variadic arguments after optional arguments #307

Merged
merged 2 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,12 @@ export interface NullShouldBeTreatedAsUndefinedData {
arrayWithThreeElementsAndUndefinedAsSecondArgument: any[];
}

export class DontComplainAboutVariadicAfterOptional {
public optionalAndVariadic(optional?: string, ...things: string[]) {
return `${optional} and ${things.join(',')}`;
}
}

/**
* jsii#298: show default values in sphinx documentation, and respect newlines.
**/
Expand All @@ -1012,7 +1018,7 @@ export interface LoadBalancedFargateServiceProps {
* @default 256
*/
cpu?: string;

/**
* The amount (in MiB) of memory used by the task.
*
Expand All @@ -1034,21 +1040,21 @@ export interface LoadBalancedFargateServiceProps {
* @default 512
*/
memoryMiB?: string;

/**
* The container port of the application load balancer attached to your Fargate service. Corresponds to container port mapping.
*
* @default 80
*/
containerPort?: number;

/**
* Determines whether the Application Load Balancer will be internet-facing
*
* @default true
*/
publicLoadBalancer?: boolean;

/**
* Determines whether your Fargate Service will be assigned a public IP address.
*
Expand Down
36 changes: 35 additions & 1 deletion packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,40 @@
],
"name": "DoNotRecognizeAnyAsOptional"
},
"jsii-calc.DontComplainAboutVariadicAfterOptional": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.DontComplainAboutVariadicAfterOptional",
"initializer": {
"initializer": true
},
"kind": "class",
"methods": [
{
"name": "optionalAndVariadic",
"parameters": [
{
"name": "optional",
"type": {
"optional": true,
"primitive": "string"
}
},
{
"name": "things",
"type": {
"primitive": "string"
},
"variadic": true
}
],
"returns": {
"primitive": "string"
},
"variadic": true
}
],
"name": "DontComplainAboutVariadicAfterOptional"
},
"jsii-calc.DoubleTrouble": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.DoubleTrouble",
Expand Down Expand Up @@ -3612,5 +3646,5 @@
}
},
"version": "0.7.8",
"fingerprint": "3UAOWGBZzphiNp40hKAbXcsM27uWdwmXnbiPU74ZroU="
"fingerprint": "MNdOxOP9VioCZlGXuccW1Zu64GAKSSIg93bLN+YDPYE="
}
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,40 @@
],
"name": "DoNotRecognizeAnyAsOptional"
},
"jsii-calc.DontComplainAboutVariadicAfterOptional": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.DontComplainAboutVariadicAfterOptional",
"initializer": {
"initializer": true
},
"kind": "class",
"methods": [
{
"name": "optionalAndVariadic",
"parameters": [
{
"name": "optional",
"type": {
"optional": true,
"primitive": "string"
}
},
{
"name": "things",
"type": {
"primitive": "string"
},
"variadic": true
}
],
"returns": {
"primitive": "string"
},
"variadic": true
}
],
"name": "DontComplainAboutVariadicAfterOptional"
},
"jsii-calc.DoubleTrouble": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.DoubleTrouble",
Expand Down Expand Up @@ -3612,5 +3646,5 @@
}
},
"version": "0.7.8",
"fingerprint": "3UAOWGBZzphiNp40hKAbXcsM27uWdwmXnbiPU74ZroU="
"fingerprint": "MNdOxOP9VioCZlGXuccW1Zu64GAKSSIg93bLN+YDPYE="
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace
{
[JsiiClass(typeof(DontComplainAboutVariadicAfterOptional), "jsii-calc.DontComplainAboutVariadicAfterOptional", "[]")]
public class DontComplainAboutVariadicAfterOptional : DeputyBase
{
public DontComplainAboutVariadicAfterOptional(): base(new DeputyProps(new object[]{}))
{
}

protected DontComplainAboutVariadicAfterOptional(ByRefValue reference): base(reference)
{
}

protected DontComplainAboutVariadicAfterOptional(DeputyProps props): base(props)
{
}

[JsiiMethod("optionalAndVariadic", "{\"primitive\":\"string\"}", "[{\"name\":\"optional\",\"type\":{\"primitive\":\"string\",\"optional\":true}},{\"name\":\"things\",\"type\":{\"primitive\":\"string\"}}]")]
public virtual string OptionalAndVariadic(string optional, string things)
{
return InvokeInstanceMethod<string>(new object[]{optional, things});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
case "jsii-calc.DerivedStruct": return software.amazon.jsii.tests.calculator.DerivedStruct.class;
case "jsii-calc.DoNotOverridePrivates": return software.amazon.jsii.tests.calculator.DoNotOverridePrivates.class;
case "jsii-calc.DoNotRecognizeAnyAsOptional": return software.amazon.jsii.tests.calculator.DoNotRecognizeAnyAsOptional.class;
case "jsii-calc.DontComplainAboutVariadicAfterOptional": return software.amazon.jsii.tests.calculator.DontComplainAboutVariadicAfterOptional.class;
case "jsii-calc.DoubleTrouble": return software.amazon.jsii.tests.calculator.DoubleTrouble.class;
case "jsii-calc.GiveMeStructs": return software.amazon.jsii.tests.calculator.GiveMeStructs.class;
case "jsii-calc.IFriendlier": return software.amazon.jsii.tests.calculator.IFriendlier.class;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package software.amazon.jsii.tests.calculator;

@javax.annotation.Generated(value = "jsii-pacmak")
@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.DontComplainAboutVariadicAfterOptional")
public class DontComplainAboutVariadicAfterOptional extends software.amazon.jsii.JsiiObject {
protected DontComplainAboutVariadicAfterOptional(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
super(mode);
}
public DontComplainAboutVariadicAfterOptional() {
super(software.amazon.jsii.JsiiObject.InitializationMode.Jsii);
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this);
}

public java.lang.String optionalAndVariadic(@javax.annotation.Nullable final java.lang.String optional, final java.lang.String... things) {
return this.jsiiCall("optionalAndVariadic", java.lang.String.class, java.util.stream.Stream.concat(java.util.stream.Stream.of(optional), java.util.Arrays.stream(java.util.Objects.requireNonNull(things, "things is required"))).toArray());
}
}
37 changes: 37 additions & 0 deletions packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,43 @@ DoNotRecognizeAnyAsOptional
:type _optionalString: string *(optional)*


DontComplainAboutVariadicAfterOptional
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. py:class:: DontComplainAboutVariadicAfterOptional()

**Language-specific names:**

.. tabs::

.. code-tab:: c#

using Amazon.JSII.Tests.CalculatorNamespace;

.. code-tab:: java

import software.amazon.jsii.tests.calculator.DontComplainAboutVariadicAfterOptional;

.. code-tab:: javascript

const { DontComplainAboutVariadicAfterOptional } = require('jsii-calc');

.. code-tab:: typescript

import { DontComplainAboutVariadicAfterOptional } from 'jsii-calc';




.. py:method:: optionalAndVariadic(optional, *things) -> string

:param optional:
:type optional: string *(optional)*
:param \*things:
:type \*things: string
:rtype: string


DoubleTrouble
^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion packages/jsii/lib/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ export class Assembler implements Emitter {

let optional = false;
for (const p of parameters) {
if (optional && !p.type.optional) {
if (optional && !p.type.optional && !p.variadic) {
this._diagnostic(node, ts.DiagnosticCategory.Error,
`Parameter ${p.name} must be optional since it comes after an optional parameter`);
}
Expand Down