aws / aws/jsii

Java: union of arrays produces a compilation failure

Open
#5,087 0 comments 0 reactions 0 assignees View on GitHub
bug effort/small needs-triage p1
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

### Describe the bug

The following:

```ts
export type X = A[] | B[] | C;
```

Fails to compile in Java, because type erasure turns this into 2 arrays.

The following does work:

```ts
export type X = (A | B)[] | C;
```

jsii-compiler should reject the former.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Expected Behavior

If it passes the compiler it shouldn't fail packaging.

### Current Behavior

The opposite.

### Reproduction Steps

SEe description.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### SDK version used

-

### Environment details (OS name and version, etc.)

-

Contributor guide

Open the contributing guide

Research direction

Start by tracing the jsii-compiler validation path for exported union types and reproduce the two TypeScript declarations through Java packaging. Compare the accepted union-of-arrays case with the working parenthesized form, then add coverage showing that the former is rejected before packaging. Done means the compiler reports the invalid Java-erasure case clearly and the valid form still packages.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.