Skip to content

Commit

Permalink
fix(aws-lambda): java - invalid cast for inline LambdaRuntime members (
Browse files Browse the repository at this point in the history
…#505)

TypeScript uses inference to determine if a cast to an interface is legal but
strongly-typed languages like Java require that the down-casted class will
explicitly implement the interface.

The JavaRuntime class has static members that are down-casted from JavaRuntime
to a set of interfaces, to allow strong-typing of properties for various Lambda
use cases. These down-casts fail in e.g. Java because JavaRuntime doesn't implement
these interfaces explicitly.

We should add a compile-time check in jsii for such a use case.

Fixes #504
  • Loading branch information
Elad Ben-Israel authored Aug 6, 2018
1 parent 4fec0cb commit bd18456
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/@aws-cdk/aws-lambda/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ export interface LambdaRuntimeProps {
/**
* Lambda function runtime environment.
*/
export class LambdaRuntime {
export class LambdaRuntime implements InlinableLambdaRuntime, InlinableJavascriptLambdaRuntime {
public static readonly NodeJS = new LambdaRuntime('nodejs', { supportsInlineCode: true }) as InlinableJavascriptLambdaRuntime;
// Using ``as InlinableLambdaRuntime`` because that calss cannot be defined just yet
// Using ``as InlinableLambdaRuntime`` because that class cannot be defined just yet
public static readonly NodeJS43 = new LambdaRuntime('nodejs4.3', { supportsInlineCode: true }) as InlinableJavascriptLambdaRuntime;
public static readonly NodeJS43Edge = new LambdaRuntime('nodejs4.3-edge');
// Using ``as InlinableLambdaRuntime`` because that calss cannot be defined just yet
// Using ``as InlinableLambdaRuntime`` because that class cannot be defined just yet
public static readonly NodeJS610 = new LambdaRuntime('nodejs6.10', { supportsInlineCode: true }) as InlinableJavascriptLambdaRuntime;
public static readonly NodeJS810 = new LambdaRuntime('nodejs8.10');
public static readonly Java8 = new LambdaRuntime('java8');
// Using ``as InlinableLambdaRuntime`` because that calss cannot be defined just yet
// Using ``as InlinableLambdaRuntime`` because that class cannot be defined just yet
public static readonly Python27 = new LambdaRuntime('python2.7', { supportsInlineCode: true }) as InlinableLambdaRuntime;
// Using ``as InlinableLambdaRuntime`` because that calss cannot be defined just yet
// Using ``as InlinableLambdaRuntime`` because that class cannot be defined just yet
public static readonly Python36 = new LambdaRuntime('python3.6', { supportsInlineCode: true }) as InlinableLambdaRuntime;
public static readonly DotNetCore1 = new LambdaRuntime('dotnetcore1.0');
public static readonly DotNetCore2 = new LambdaRuntime('dotnetcore2.0');
Expand Down Expand Up @@ -48,7 +48,7 @@ export class LambdaRuntime {
*/
export interface InlinableLambdaRuntime {
readonly name: string;
readonly supportsInlineCode: true;
readonly supportsInlineCode: boolean;
}

/**
Expand Down

0 comments on commit bd18456

Please sign in to comment.