Skip to content

Commit

Permalink
fix(dotnet): fix callback issues (#953)
Browse files Browse the repository at this point in the history
* fix(dotnet): fix callback issues

Corrects an issue with handling callbacks in various situations:
- When a callback for a method with optional parameters was invoked with
  some of the optional parameters not specified, an argument count
  mismatch error would occur. This is because dotnet reflection requires
  all arguments to be provided (with `null` if needed).
- When a callback for a variadic method was invoked, a type mismatch or
  a parameter count mismatch error would occur. This is because the
  variadic parameter is an array of it's value type, and has to be
  passed this way out to the reflection call.
- Objects would be created in Javascript without interface annotations,
  causing type information to be lost and incorrect callback argument
  serialization could happen in the Kernel.
- When a class implements members from an interface (and only from one),
  the overrides would not be correctly identified, as the Attributes on
  interface members are *not* visible on the implementors (whereas they
  are visible when they were on an extended class member!).
- Invalid type coertion could happen within the callback handling logic
  in certain edge cases. The complete type information is available, so
  switched to using the full conversion gear form the jsii runtime to
  achieve correct results.

All of those issues are fairly inter-linked and it was difficult to fix
them individually & issue a test that would not break due to another of
the issues... Hence the fixes are grouped in a single commit.

* fixup test expectations I had forgot to care about 🤷🏻‍♂️
  • Loading branch information
RomainMuller authored and mergify[bot] committed Nov 7, 2019
1 parent 896d688 commit 849c004
Show file tree
Hide file tree
Showing 18 changed files with 1,470 additions and 793 deletions.
22 changes: 21 additions & 1 deletion packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,15 @@ export class VariadicMethod {
}
}

export class VariadicInvoker {
public constructor(private readonly method: VariadicMethod) { }

public asArray(...values: number[]): number[] {
const [first, ...rest] = values;
return this.method.asArray(first, ...rest);
}
}

export class Statics {
constructor(public readonly value: string) {
}
Expand Down Expand Up @@ -1063,6 +1072,17 @@ export namespace InterfaceInNamespaceIncludesClasses {
export interface IInterfaceWithOptionalMethodArguments {
hello(arg1: string, arg2?: number): void
}
export class OptionalArgumentInvoker {
constructor(private readonly delegate: IInterfaceWithOptionalMethodArguments) { }

public invokeWithoutOptional() {
return this.delegate.hello('Howdy');
}

public invokeWithOptional() {
return this.delegate.hello('Howdy', 1337);
}
}

/**
* awslabs/jsii#220
Expand Down Expand Up @@ -2154,4 +2174,4 @@ class PrivateBell implements IBell {
public ring() {
this.rung = true;
}
}
}
Loading

0 comments on commit 849c004

Please sign in to comment.