Skip to content

validating assignment of functions to object literal method types#1136

Merged
Perryvw merged 2 commits intoTypeScriptToLua:masterfrom
tomblind:validate-object-literal-method
Sep 13, 2021
Merged

validating assignment of functions to object literal method types#1136
Perryvw merged 2 commits intoTypeScriptToLua:masterfrom
tomblind:validate-object-literal-method

Conversation

@tomblind
Copy link
Collaborator

@tomblind tomblind commented Sep 12, 2021

Adds correct validation for cases where a function is being indirectly assigned to a type defined as an object literal method.

Example:

function out(this: void, val: string) {
  print(val);
}

function bug(input: { consumer: (val: string) => void }) {
    input.consumer("test");
}

bug({ consumer: out }); // Should fail function assignment validation

Playground

"Invalid object with method assignment with cast (%p, %p, %p)",
(testFunction, castedFunction, isSelfConversion) => {
util.testModule`
${testFunction.definition ?? ""}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this indenting seems weird, it's different from the other tests in the diff

"Valid object with method assignment with cast (%p, %p)",
(testFunction, castedFunction) => {
util.testFunction`
let obj: { fn: typeof ${testFunction.value} };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this indenting is weird too

@tomblind tomblind requested a review from Perryvw September 12, 2021 19:50
@Perryvw Perryvw merged commit 0364cdf into TypeScriptToLua:master Sep 13, 2021
Perryvw pushed a commit that referenced this pull request Sep 14, 2021
)

* validating assignment of functions to object literal method types

* fixed indentation in tests

Co-authored-by: Tom <tomblind@users.noreply.github.com>
sanikoyes pushed a commit to sanikoyes/TypeScriptToLua that referenced this pull request Sep 24, 2021
…peScriptToLua#1136)

* validating assignment of functions to object literal method types

* fixed indentation in tests

Co-authored-by: Tom <tomblind@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants