Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add error message#10446

Merged
sandersn merged 6 commits into
microsoft:mastermicrosoft/TypeScript:masterfrom
YuichiNukiyama:fix10351YuichiNukiyama/TypeScript:fix10351Copy head branch name to clipboard
Aug 23, 2016
Merged

Add error message#10446
sandersn merged 6 commits into
microsoft:mastermicrosoft/TypeScript:masterfrom
YuichiNukiyama:fix10351YuichiNukiyama/TypeScript:fix10351Copy head branch name to clipboard

Conversation

@YuichiNukiyama

Copy link
Copy Markdown
Contributor

Fixes #10351
Reference https://developer.mozilla.org/en-US/docs/Glossary/Primitive
Add error message when trying to relate primitives to the boxed/apparent backing types.

Add error message when trying to relate primitives to the boxed/apparent
backing types.
Comment thread src/compiler/checker.ts Outdated
}

// check if trying to relate primitives to the boxed/apparent backing types.
if ((sourceType === "Number" && targetType === "number") ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You don't want to do this because you might be in a context where Number has been shadowed to something else.

You also need to cover Symbol/symbol.

Instead, do a check against

  • globalStringType/stringType
  • globalNumberType/numberType
  • globalBooleanType/booleanType
  • getGlobalESSymbolType()/esSymbolType

@DanielRosenwasser DanielRosenwasser Aug 20, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, I don't think you necessarily want to do this here. I think you want to have a separate function for this logic right before this line in isRelatedTo:

if (reportErrors) {
    reportRelationError(headMessage, source, target);
}

So before that, I'd have a check like

if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.Primitive) {
    tryElaborateErrorsForPrimitivesAndObjects(source, target);
}

@DanielRosenwasser

Copy link
Copy Markdown
Member

Looks like a nice improvement in the baselines! 😄

@YuichiNukiyama

YuichiNukiyama commented Aug 20, 2016

Copy link
Copy Markdown
Contributor Author

@DanielRosenwasser Thanks your kindfull advise. I have no idea why some tests fail. Do you have any ideas?

@DanielRosenwasser

DanielRosenwasser commented Aug 20, 2016

Copy link
Copy Markdown
Member

Whoops - that's being caused by the assertion in reportError. Basically you'll need to move the new change into the

if (reportErrors) {
    // ...
}

block in isRelatedTo.

@YuichiNukiyama

Copy link
Copy Markdown
Contributor Author

@DanielRosenwasser Nice 👍 I could resolve my issues.

@DanielRosenwasser

Copy link
Copy Markdown
Member

Nice job! @RyanCavanaugh and @sandersn, any feedback?

@RyanCavanaugh

Copy link
Copy Markdown
Member

The ES spec refers to these as "wrapper objects" and doesn't use the term "box". I would prefer something like

'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.

Thoughts?

@DanielRosenwasser

Copy link
Copy Markdown
Member

Let's go with Ryan's suggestion and I think we'll be good to pull in.

@YuichiNukiyama

Copy link
Copy Markdown
Contributor Author

change error message.

@sandersn sandersn merged commit ddb5a00 into microsoft:master Aug 23, 2016
@YuichiNukiyama YuichiNukiyama deleted the fix10351 branch August 23, 2016 21:34
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.