GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Give more helpful error when trying to set default values on an interface. by delta-nry · Pull Request #5736 · microsoft/TypeScript

Conversation

@delta-nry

@delta-nry Nathan Yee (delta-nry) commented Nov 20, 2015

Copy link
Copy Markdown
Contributor

Fixes #5173 - Give more helpful error when trying to set default values on an interface.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Nathan Yee (delta-nry) added 3 commits November 20, 2015 08:30
@delta-nry
Implement microsoft#5173
c93f454
Give more helpful error when trying to set default values on an
interface
@delta-nry
Fix object type literal regression
40a2a25
@delta-nry
Clarify comment
5b3d299
@msftclas

Microsoft Contribution License Agreements (msftclas) commented Nov 20, 2015

Copy link
Copy Markdown

Hi Nathan Yee (@delta-nry), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla.microsoft.com.

TTYL, MSBOT;

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-required label Nov 20, 2015
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) changed the title Issue 5173 Give more helpful error when trying to set default values on an interface. Nov 20, 2015
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Nov 20, 2015

Copy link
Copy Markdown
Member

Hey Nathan Yee (@delta-nry) - thanks for the PR. I notice that there's no test case affected - can you add a few tests as per our contribution guidelines?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@delta-nry

Nathan Yee (delta-nry) commented Nov 20, 2015

Copy link
Copy Markdown
Contributor Author

Thanks for the quick reply Daniel Rosenwasser (@DanielRosenwasser). As I am part of a group of students from the University of British Columbia, I am waiting for my partners to implement the test case(s) you requested. Thus, we may get back to you sometime within two weeks. Thank you for your patience on resolving this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Nov 21, 2015

Copy link
Copy Markdown
Member

No worries, just keep us posted since GitHub doesn't send updates for new commits.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@delta-nry
Add tests for microsoft#5173
068d10c
@msftclas

Microsoft Contribution License Agreements (msftclas) commented Nov 25, 2015

Copy link
Copy Markdown

Nathan Yee (@delta-nry), Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, MSBOT;

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@msftclas Microsoft Contribution License Agreements (msftclas) added cla-signed and removed cla-required labels Nov 25, 2015
@delta-nry

Nathan Yee (delta-nry) commented Nov 25, 2015

Copy link
Copy Markdown
Contributor Author

I have implemented the required tests. In the interest of full disclosure, I am the sole person who implemented these tests and none of the content of these tests are original works of my partners. Thank you for your patience regarding this issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DanielRosenwasser
DanielRosenwasser reviewed Nov 25, 2015
View reviewed changes
Comment thread src/compiler/parser.ts Outdated

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Nov 25, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You can just pass parseNonParameterInitializer to lookahead. Testing truthiness is fine here, and you'll avoid allocating a closure.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@CyrusNajmabadi Cyrus Najmabadi (CyrusNajmabadi) Nov 25, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I would not do it this way. I would just parse out an initializer for these properties. Then, in the checker, detect that and report a nice error there.

We do not want random errors being produced the parser like this.

The benefit of this is that now our tree is well formed. And you can do things like format the tree nicely and have the rest of our features not barf when this is encountered.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Nov 26, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

So to summarize Nathan Yee (@delta-nry), just add an optional initializer onto each PropertySignature and perform a grammar check in checker.ts on each property. Report the error on the initializer or the node itself.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Nov 25, 2015

Copy link
Copy Markdown
Member

Cyrus Najmabadi (@CyrusNajmabadi) can you take a quick look?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DanielRosenwasser
DanielRosenwasser reviewed Nov 25, 2015
View reviewed changes
Comment thread tests/baselines/reference/errorOnInitializerInObjectType.errors.txt Outdated

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Nov 25, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'm surprised that we don't go off the rails here since you're not advancing the parser at all (i.e. you use lookAhead, not tryParse).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Nov 25, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Actually, this is because the parser tries to be smart and avoids reporting more errors at the same start position. I'm not sure if that's the right thing to do because instead of gracefully parsing the invalid initializer, the parser can start going haywire down the line. Maybe tryParse would be better? What do you think Cyrus Najmabadi (@CyrusNajmabadi)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@CyrusNajmabadi Cyrus Najmabadi (CyrusNajmabadi) Nov 25, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We should just allow initializers. This is a pretty reasonable thing for a user to type, so the tree shoudl just be flexible enough to represent it. We can hten have a simple grammar check in the type checker that reports that thsi isn't legal.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@delta-nry
Report property errors in the checker instead of the parser
6c755c9
DanielRosenwasser
DanielRosenwasser reviewed Nov 28, 2015
View reviewed changes
Comment thread src/compiler/checker.ts Outdated

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Nov 28, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You should be performing this check in any type literal, not just those in variable like declarations.

I think you should just move the check into checkGrammarProperty, and discriminate on whether you have a PropertySignature with an initializer.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Nov 28, 2015

Copy link
Copy Markdown
Member

Nathan Yee (@delta-nry), I left some feedback. Basically, you should perform the grammar check in checkGrammarProperty.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@delta-nry
Move initializer checks into checkGrammarProperty
d9d67d9
delta-nry
delta-nry reviewed Nov 28, 2015
View reviewed changes
Comment thread tests/baselines/reference/objectTypeLiteralSyntax2.errors.txt Outdated

@delta-nry Nathan Yee (delta-nry) Nov 28, 2015

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'm not sure if we should accept these errors, as the '=' expected message implies that initializers are allowed in this case. Maybe we should spin this off into a new issue. Daniel Rosenwasser (@DanielRosenwasser) Cyrus Najmabadi (@CyrusNajmabadi), what are your thoughts on this?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Nov 28, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It should be sufficient if you make it so that you only try to parse an initializer if the current token is a =.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@delta-nry
Revert baseline changes to the objectTypeLiteralSyntax2 test
e363c75
@delta-nry

Nathan Yee (delta-nry) commented Nov 30, 2015

Copy link
Copy Markdown
Contributor Author

Daniel Rosenwasser (@DanielRosenwasser), Cyrus Najmabadi (@CyrusNajmabadi) how do these fixes look?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DanielRosenwasser
DanielRosenwasser reviewed Dec 1, 2015
View reviewed changes
Comment thread src/compiler/diagnosticMessages.json Outdated

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Dec 1, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Sorry I didn't notice it earlier, but this should be "A type literal property"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Dec 1, 2015

Copy link
Copy Markdown
Member

I think this is great - just address the last comments I left and we should be good to merge. 😃

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@delta-nry
Change "object type literal" to "type literal"
144d24c
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Dec 1, 2015

Copy link
Copy Markdown
Member

💯

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@delta-nry @msftclas @DanielRosenwasser @CyrusNajmabadi
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.