Skip to content

Unify the way anonymous class symbols are printed in error messages #731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10984,7 +10984,7 @@ func (c *Checker) checkPrivateIdentifierPropertyAccess(leftType *Type, right *as
return true
}
}
c.error(right, diagnostics.Property_0_is_not_accessible_outside_class_1_because_it_has_a_private_identifier, diagName, scanner.DeclarationNameToString(typeClass.Name()))
c.error(right, diagnostics.Property_0_is_not_accessible_outside_class_1_because_it_has_a_private_identifier, diagName, c.SymbolToString(typeClass.Symbol()))
return true
}
return false
Expand Down
5 changes: 1 addition & 4 deletions internal/checker/relater.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/jsnum"
"github.com/microsoft/typescript-go/internal/scanner"
)

type SignatureCheckMode uint32
Expand Down Expand Up @@ -4269,9 +4268,7 @@ func (r *Relater) reportUnmatchedProperty(source *Type, target *Type, unmatchedP
privateIdentifierDescription := unmatchedProperty.ValueDeclaration.Name().Text()
symbolTableKey := binder.GetSymbolNameForPrivateIdentifier(source.symbol, privateIdentifierDescription)
if r.c.getPropertyOfType(source, symbolTableKey) != nil {
sourceName := scanner.DeclarationNameToString(ast.GetNameOfDeclaration(source.symbol.ValueDeclaration))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the previous behavior here was already diverging slightly from Strada for those anonymous classes (IMHO, in a good way)

targetName := scanner.DeclarationNameToString(ast.GetNameOfDeclaration(target.symbol.ValueDeclaration))
r.reportError(diagnostics.Property_0_in_type_1_refers_to_a_different_member_that_cannot_be_accessed_from_within_type_2, privateIdentifierDescription, sourceName, targetName)
r.reportError(diagnostics.Property_0_in_type_1_refers_to_a_different_member_that_cannot_be_accessed_from_within_type_2, privateIdentifierDescription, r.c.SymbolToString(source.symbol), r.c.SymbolToString(target.symbol))
return
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
privateNameMethodClassExpression.ts(9,17): error TS18013: Property '#method' is not accessible outside class '(Missing)' because it has a private identifier.
privateNameMethodClassExpression.ts(10,17): error TS18013: Property '#field' is not accessible outside class '(Missing)' because it has a private identifier.
privateNameMethodClassExpression.ts(9,17): error TS18013: Property '#method' is not accessible outside class 'C' because it has a private identifier.
privateNameMethodClassExpression.ts(10,17): error TS18013: Property '#field' is not accessible outside class 'C' because it has a private identifier.


==== privateNameMethodClassExpression.ts (2 errors) ====
Expand All @@ -13,9 +13,9 @@ privateNameMethodClassExpression.ts(10,17): error TS18013: Property '#field' is
console.log(C.getInstance().getField());
C.getInstance().#method; // Error
~~~~~~~
!!! error TS18013: Property '#method' is not accessible outside class '(Missing)' because it has a private identifier.
!!! error TS18013: Property '#method' is not accessible outside class 'C' because it has a private identifier.
C.getInstance().#field; // Error
~~~~~~
!!! error TS18013: Property '#field' is not accessible outside class '(Missing)' because it has a private identifier.
!!! error TS18013: Property '#field' is not accessible outside class 'C' because it has a private identifier.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strada would print (anonymous) here but this has an inferrable~ name from the declaration and I think it's better to use it. Using it is not a new thing to do.



Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
@@= skipped -0, +0 lines =@@
-privateNameMethodClassExpression.ts(9,17): error TS18013: Property '#method' is not accessible outside class '(anonymous)' because it has a private identifier.
-privateNameMethodClassExpression.ts(10,17): error TS18013: Property '#field' is not accessible outside class '(anonymous)' because it has a private identifier.
+privateNameMethodClassExpression.ts(9,17): error TS18013: Property '#method' is not accessible outside class '(Missing)' because it has a private identifier.
+privateNameMethodClassExpression.ts(10,17): error TS18013: Property '#field' is not accessible outside class '(Missing)' because it has a private identifier.
+privateNameMethodClassExpression.ts(9,17): error TS18013: Property '#method' is not accessible outside class 'C' because it has a private identifier.
+privateNameMethodClassExpression.ts(10,17): error TS18013: Property '#field' is not accessible outside class 'C' because it has a private identifier.


==== privateNameMethodClassExpression.ts (2 errors) ====
Expand All @@ -13,10 +13,10 @@
C.getInstance().#method; // Error
~~~~~~~
-!!! error TS18013: Property '#method' is not accessible outside class '(anonymous)' because it has a private identifier.
+!!! error TS18013: Property '#method' is not accessible outside class '(Missing)' because it has a private identifier.
+!!! error TS18013: Property '#method' is not accessible outside class 'C' because it has a private identifier.
C.getInstance().#field; // Error
~~~~~~
-!!! error TS18013: Property '#field' is not accessible outside class '(anonymous)' because it has a private identifier.
+!!! error TS18013: Property '#field' is not accessible outside class '(Missing)' because it has a private identifier.
+!!! error TS18013: Property '#field' is not accessible outside class 'C' because it has a private identifier.