Skip to content

Offer per-member diagnostics for incorrectly implemented inherited members#21036

Merged
weswigham merged 3 commits into
microsoft:masterfrom
weswigham:better-incorrect-impl-error
Jan 9, 2018
Merged

Offer per-member diagnostics for incorrectly implemented inherited members#21036
weswigham merged 3 commits into
microsoft:masterfrom
weswigham:better-incorrect-impl-error

Conversation

@weswigham
Copy link
Copy Markdown
Member

If possible, this causes us to issue a diagnostic on each property which is not compatible with the base type, rather than just the class name. This should assist with identifying and correcting problem properties, since the reason for each property's mismatch will now be listed (if there are multiple which do not match).

Fixes #20980.

@alfaproject
Copy link
Copy Markdown

Is it possible to have the name of the member and not just the type?

Comment thread src/compiler/diagnosticMessages.json Outdated
"category": "Error",
"code": 2415
},
"Class member of type '{0}' is not assignable to base class member of type '{1}'.": {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i would add the member name as well..

Copy link
Copy Markdown
Contributor

@mhegazy mhegazy Jan 8, 2018

Choose a reason for hiding this comment

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

The error message before was helpful too. i wounder if we should make this an elaboration, e.g.:

Class '{0}' incorrectly extends base class '{1}'.
   Member '{2}' of type '{3}' is not assignable to base class member of type '{3}'.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also pinging @DanielRosenwasser

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

With a little more in-person deliberation, I've changed it to the following:

Property 'bar' in type 'B' is not assignable to the same property in base type 'Base'.
   Type 'string' is not assignable to type 'Base'.

@weswigham weswigham force-pushed the better-incorrect-impl-error branch from a9995ce to b563c1a Compare January 8, 2018 23:14
Comment thread src/compiler/checker.ts Outdated
}

function issueMemberSpecificError(node: ClassLikeDeclaration, typeWithThis: Type, baseWithThis: Type, specificDiag: DiagnosticMessage, broadDiag: DiagnosticMessage) {
// iterate over all implemented properties and issue errors on each one which isn't compatible, ratehr than the class as a whole, if possible
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.

typo:rather

Comment thread src/compiler/checker.ts Outdated
}

function issueMemberSpecificError(node: ClassLikeDeclaration, typeWithThis: Type, baseWithThis: Type, broadDiag: DiagnosticMessage) {
// iterate over all implemented properties and issue errors on each one which isn't compatible, ratehr than the class as a whole, if possible
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.

typo:rather

!!! error TS2416: Types of property 'n' are incompatible.
!!! error TS2416: Type 'string | DerivedInterface' is not assignable to type 'string | Base'.
!!! error TS2416: Type 'DerivedInterface' is not assignable to type 'string | Base'.
!!! error TS2416: Type 'DerivedInterface' is not assignable to type 'Base'.
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.

:(

Is this better than the old error?

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.

After in-person discussion:

  1. It is the same as the old error, but at least the correct error is reported below.
  2. It's not that bad because we believe recursive-typed properties aren't that common, so there will not be many bogus errors showing up along with the real one.

@weswigham weswigham merged commit fdd8a52 into microsoft:master Jan 9, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 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.

4 participants