Skip to content

Commit 87b8df8

Browse files
committed
fix: don't mark invalid symbols as companion objects
1 parent 10d2a52 commit 87b8df8

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

effect/packages/package1/src/companions-everywhere.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,3 @@ export const get: A = {}
1313
* @tsplus static companions-everywhere/AOps __call
1414
*/
1515
export const callA = (): A => ({})
16-
17-
class X {}
18-
19-
new X()
20-
X
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import { Async } from '@fp-ts/core/Async'
22

33
Async.fromSync(() => console.log("Fluent in fp-ts!")).delay(1)
4-

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/checker.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,16 +2790,19 @@ namespace ts {
27902790
if (symbol) {
27912791
if (companionSymbolCache.has(symbol)) {
27922792
result = symbol;
2793+
getSymbolLinks(symbol).isPossibleCompanionReference = true;
27932794
break loop;
27942795
}
27952796
if (symbol.exportSymbol && companionSymbolCache.has(symbol.exportSymbol)) {
27962797
result = symbol.exportSymbol;
2798+
getSymbolLinks(symbol.exportSymbol).isPossibleCompanionReference = true;
27972799
break loop;
27982800
}
27992801
if (symbol.declarations && symbol.declarations[0] && isImportSpecifier(symbol.declarations[0])) {
28002802
const originalSymbol = getTargetOfImportSpecifier(symbol.declarations[0], false);
28012803
if (originalSymbol && companionSymbolCache.has(originalSymbol)) {
28022804
result = originalSymbol;
2805+
getSymbolLinks(originalSymbol).isPossibleCompanionReference = true;
28032806
symbol.isReferenced = SymbolFlags.Value;
28042807
break loop;
28052808
}
@@ -5837,8 +5840,21 @@ namespace ts {
58375840
if (!type) {
58385841
return false
58395842
}
5840-
return !!(getObjectFlags(type) & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & SymbolFlags.Class)
5841-
|| (!!symbol?.declarations?.[0] && (isInterfaceDeclaration(symbol.declarations[0]) || isTypeAliasDeclaration(symbol.declarations[0])))
5843+
5844+
// Class companion object
5845+
if (getObjectFlags(type) & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & SymbolFlags.Class) {
5846+
return true
5847+
}
5848+
5849+
// Synthetic Interface or TypeAlias companion object
5850+
if (symbol && symbol.declarations && symbol.declarations.length > 0) {
5851+
const declaration = symbol.declarations[0]
5852+
if (isInterfaceDeclaration(declaration) || isTypeAliasDeclaration(declaration)) {
5853+
return !!getSymbolLinks(symbol).isPossibleCompanionReference;
5854+
}
5855+
}
5856+
5857+
return false
58425858
}
58435859
// TSPLUS EXTENSION END
58445860

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5817,6 +5817,7 @@ namespace ts {
58175817
type: Type,
58185818
tags: Set<string>
58195819
}
5820+
isPossibleCompanionReference?: boolean
58205821
// TSPLUS END
58215822
}
58225823

0 commit comments

Comments
 (0)