Segmentation fault
Closed this issue · 7 comments
Stack trace
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x104f1abc8]
goroutine 1198 [running]:
github.com/microsoft/typescript-go/internal/ast.(*Node).Text(0x140012e4008?)
external/_main~_repo_rules~typescript_go/internal/ast/ast.go:304 +0x18
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(0x140012e4008, 0x140021317a0, 0x14008d4de78?)
external/_main~_repo_rules~typescript_go/internal/checker/checker.go:13892 +0x1f8
github.com/microsoft/typescript-go/internal/checker.(*Checker).getTargetOfImportEqualsDeclaration(0x140012e4008, 0x140021317a0, 0x20?)
external/_main~_repo_rules~typescript_go/internal/checker/checker.go:13842 +0x1a8
github.com/microsoft/typescript-go/internal/checker.(*Checker).getTargetOfAliasDeclaration(0x140012e48e8?, 0x100e43060?, 0x0?)
external/_main~_repo_rules~typescript_go/internal/checker/checker.go:15036 +0xb4
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveAlias(0x140012e4008, 0x140042be000)
external/_main~_repo_rules~typescript_go/internal/checker/checker.go:15522 +0x12c
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveSymbolEx(0x100c6f560?, 0x14009365800?, 0x0?)
external/_main~_repo_rules~typescript_go/internal/checker/checker.go:13824 +0x44
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveSymbol(...)
external/_main~_repo_rules~typescript_go/internal/checker/checker.go:13819
github.com/microsoft/typescript-go/internal/checker.(*Checker).getSymbolIfSameReference(0x140012e4008, 0x140042be000, 0x140089348c8)
external/_main~_repo_rules~typescript_go/internal/checker/checker.go:13767 +0x68
github.com/microsoft/typescript-go/internal/checker.(*Checker).getAliasForSymbolInContainer(0x140012e4008, 0x140066f02a0, 0x140089348c8)
external/_main~_repo_rules~typescript_go/internal/checker/symbolaccessibility.go:364 +0x190
github.com/microsoft/typescript-go/internal/checker.(*Checker).getAlternativeContainingModules(0x140012e4008, 0x140089348c8, 0x140066f1dc0?)
external/_main~_repo_rules~typescript_go/internal/checker/symbolaccessibility.go:218 +0x260
github.com/microsoft/typescript-go/internal/checker.(*Checker).getWithAlternativeContainers(0x140012e4008, 0x140066f1dc0, 0x140089348c8, 0x14009c82000, 0xc09e8)
external/_main~_repo_rules~typescript_go/internal/checker/symbolaccessibility.go:125 +0x18c
github.com/microsoft/typescript-go/internal/checker.(*Checker).getContainersOfSymbol(0x140012e4008, 0x140089348c8, 0x14009c82000, 0xc09e8)
external/_main~_repo_rules~typescript_go/internal/checker/symbolaccessibility.go:334 +0x550
github.com/microsoft/typescript-go/internal/checker.(*Checker).IsAnySymbolAccessible(0x140012e4008, {0x14008d4e550, 0x1, 0x10022b398?}, 0x14009c82000, 0x140089348c8, 0xc09e8, 0x0, 0x1)
external/_main~_repo_rules~typescript_go/internal/checker/symbolaccessibility.go:76 +0x13c
github.com/microsoft/typescript-go/internal/checker.(*Checker).isSymbolAccessibleWorker(0x140012e4008, 0x140089348c8, 0x14009c82000, 0xc09e8, 0x1?, 0x0?)
external/_main~_repo_rules~typescript_go/internal/checker/symbolaccessibility.go:728 +0x70
github.com/microsoft/typescript-go/internal/checker.(*Checker).IsTypeSymbolAccessible(...)
external/_main~_repo_rules~typescript_go/internal/checker/symbolaccessibility.go:14
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).typeToTypeNode(0x140088fe1c0, 0x4?)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:2930 +0x1d0
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).mapToTypeNodes(0x140088fe1c0, {0x140007405f8, 0x1, 0x199?}, 0xa9?)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:274 +0x428
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).typeReferenceToTypeNode(0x140088fe1c0, 0x140083e1880)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:2687 +0xc58
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).typeToTypeNode(0x140088fe1c0, 0x1005e0264?)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:2949 +0x75c
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).serializeTypeForDeclaration(0x140088fe1c0, 0x1400066e0e0, 0x140001c8008?, 0x140004026a8?)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:2011 +0x2b0
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).symbolToParameterDeclaration(0x140088fe1c0, 0x14008725c08, 0x0)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:1552 +0x94
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).signatureToSignatureDeclarationHelper.func2(...)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:1713
github.com/microsoft/typescript-go/internal/core.Map[...](...)
external/_main~_repo_rules~typescript_go/internal/core/core.go:57
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).signatureToSignatureDeclarationHelper(0x140088fe1c0, 0x14003ea0700, 0xb8, 0x0)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:1710 +0x8f8
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).createTypeNodeFromObjectType(0x140088fe1c0, 0x14006728d80)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:2353 +0x160
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).visitAndTransformType(0x140088fe1c0, 0x14006728d80, 0x100e33b78)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:2747 +0x50c
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).createAnonymousTypeNode(0x140088fe1c0, 0x14006728d80)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:2473 +0x2ec
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).typeToTypeNode(0x140088fe1c0, 0x14007d87980?)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:3018 +0x5fc
github.com/microsoft/typescript-go/internal/checker.(*nodeBuilderImpl).serializeTypeForDeclaration(0x140088fe1c0, 0x140004b0410, 0x800081c0d?, 0x100e441e0?)
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilderimpl.go:2011 +0x2b0
github.com/microsoft/typescript-go/internal/checker.(*NodeBuilder).SerializeTypeForDeclaration(0x14008d4f5e0, 0x140004b0410, 0x1400805f0a0, 0x14009606540?, 0x805f0a0?, 0x140?, {0x100e441e0?, 0x14007d87980?})
external/_main~_repo_rules~typescript_go/internal/checker/nodebuilder.go:108 +0x5c
github.com/microsoft/typescript-go/internal/checker.(*emitResolver).CreateTypeOfDeclaration(0x14009c2c360, 0x14004778be0, 0x140004b0410, 0x14000678308, 0x81c0d, 0x8, {0x100e441e0, 0x14007d87980})
external/_main~_repo_rules~typescript_go/internal/checker/emitresolver.go:914 +0x378
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).ensureType(0x1400889a8c0, 0x140004b0410, 0xf8?)
external/_main~_repo_rules~typescript_go/internal/transformers/declarations/transform.go:1030 +0x284
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).transformVariableDeclaration(0x1400889a8c0, 0x140004b0410)
external/_main~_repo_rules~typescript_go/internal/transformers/declarations/transform.go:659 +0x84
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visitDeclarationSubtree(0x1400889a8c0, 0x140004b0410)
external/_main~_repo_rules~typescript_go/internal/transformers/declarations/transform.go:463 +0xa30
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visit(0x14001d7b7d8?, 0x1005a2a34?)
external/_main~_repo_rules~typescript_go/internal/transformers/declarations/transform.go:146 +0x110
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitSlice(0x140097240c0, {0x140006400f8, 0x1, 0x1})
external/_main~_repo_rules~typescript_go/internal/ast/visitor.go:148 +0xa0
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitNodes(0x140097240c0, 0x140006482a0)
external/_main~_repo_rules~typescript_go/internal/ast/visitor.go:99 +0x3c
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).transformVariableStatement(0x1400889a8c0, 0x14000802140)
external/_main~_repo_rules~typescript_go/internal/transformers/declarations/transform.go:1421 +0xcc
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).transformTopLevelDeclaration(0x1400889a8c0, 0x14000802140)
external/_main~_repo_rules~typescript_go/internal/transformers/declarations/transform.go:1113 +0x308
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visitDeclarationStatements(0x1400889a8c0, 0x14000802140)
external/_main~_repo_rules~typescript_go/internal/transformers/declarations/transform.go:953 +0x4c
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visit(0x14009c2c360?, 0x140008020a0?)
external/_main~_repo_rules~typescript_go/internal/transformers/declarations/transform.go:121 +0xe8
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitSlice(0x140097240c0, {0x14000644500, 0x2, 0x2})
external/_main~_repo_rules~typescript_go/internal/ast/visitor.go:148 +0xa0
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitNodes(0x140097240c0, 0x140006482c0)
external/_main~_repo_rules~typescript_go/internal/ast/visitor.go:99 +0x3c
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).transformSourceFile(0x1400889a8c0, 0x14000678308)
external/_main~_repo_rules~typescript_go/internal/transformers/declarations/transform.go:188 +0x30
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visitSourceFile(0x1400889a8c0, 0x14000678308)
external/_main~_repo_rules~typescript_go/internal/transformers/declarations/transform.go:175 +0x15c
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visit(0x140029a77a0?, 0xd1?)
external/_main~_repo_rules~typescript_go/internal/transformers/declarations/transform.go:105 +0xbc
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitNode(0x14001b353f0?, 0x14004778be0?)
external/_main~_repo_rules~typescript_go/internal/ast/visitor.go:51 +0x30
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitSourceFile(...)
external/_main~_repo_rules~typescript_go/internal/ast/visitor.go:36
github.com/microsoft/typescript-go/internal/transformers.(*Transformer).TransformSourceFile(...)
external/_main~_repo_rules~typescript_go/internal/transformers/transformer.go:40
github.com/microsoft/typescript-go/internal/compiler.(*emitter).emitDeclarationFile(0x14001b353f0, 0x14000678308, {0x140029a77a0, 0xd1}, {0x0, 0x0})
external/_main~_repo_rules~typescript_go/internal/compiler/emitter.go:190 +0x1a8
github.com/microsoft/typescript-go/internal/compiler.(*emitter).emit(0x14001b353f0)
external/_main~_repo_rules~typescript_go/internal/compiler/emitter.go:48 +0x48
github.com/microsoft/typescript-go/internal/compiler.(*Program).Emit.func2()
external/_main~_repo_rules~typescript_go/internal/compiler/program.go:1401 +0x194
github.com/microsoft/typescript-go/internal/core.(*parallelWorkGroup).Queue.func1()
external/_main~_repo_rules~typescript_go/internal/core/workgroup.go:42 +0x50
created by github.com/microsoft/typescript-go/internal/core.(*parallelWorkGroup).Queue in goroutine 1
external/_main~_repo_rules~typescript_go/internal/core/workgroup.go:40 +0x7c
Steps to reproduce
The below steps were not correct, updated reproduction instructions in #1731 (comment)
Minimal repro:
import {type DocsContainerProps} from '@storybook/addon-docs';
export const MyComponent = (
props: DocsContainerProps,
) => {
return null;
};
There's something about this DocsContainerProps that is tickling some bad behaviour. On the fairly large codebase I was testing tsgo on, this was the only observed segmentation fault. This is coming from "@storybook/addon-docs": "7.6.20",. Appears to work fine in legacy tsserver
Curious, what is this stack trace from? The code locations have some extra stuff at the start that makes it look like someone has imported us...
Curious, what is this stack trace from? The code locations have some extra stuff at the start that makes it look like someone has imported us...
This is being invoked with gazelle
go_repository = use_repo_rule("@bazel_gazelle//:deps.bzl", "go_repository")
go_repository(
name = "typescript_go",
commit = "1ca5a2d97b0c2b93cfc32137c8922185b4f41df0",
importpath = "github.com/microsoft/typescript-go",
)
and running with bazel run @typescript_go//cmd/tsgo
Curiously, I couldn't reproduce this error. It is prompting for errors regarding type checking, but I imagine they are expected in this case.
Tested with the same version (1ca5a2d). Isn't it something related to gazelle?
Apologies, there were some errors in my original report. I've narrowed down the issue more precisely. I do not believe the issue is related to gazelle but is the unimplemented functionality from // TODO: how to get name for export *? in internal/checker/checker.go
Here is the snippet that reproduces the crash for me:
import type * as React from 'react';
import {type DocsContainerProps} from '@storybook/addon-docs';
export const DocsContainerWithColorMode = (
props: DocsContainerProps & {
extraArgument?: boolean;
},
): React.ReactNode => {
return null;
};This slight tweak however does not reproduce the crash:
import type * as React from 'react';
import {type DocsContainerProps} from '@storybook/addon-docs';
type Props = DocsContainerProps & {
extraArgument?: boolean;
};
export const DocsContainerWithColorMode = (
props: Props,
): React.ReactNode => {
return null;
};I added some debugging output; the issue is that at the callsite in internal/ast/ast.go:
// TODO: how to get name for export *?
name := "*"
if !ast.IsExportDeclaration(typeOnlyDeclaration) {
name = getNameFromImportDeclaration(typeOnlyDeclaration).Text()
}typeOnlyDeclaration.Kind is ast.KindExportSpecifier; this appears to be what the TODO is stating.
This patch prevents the segfault:
diff --git a/internal/checker/checker.go b/internal/checker/checker.go
index b6d46d2e7..5f0be069f 100644
--- a/internal/checker/checker.go
+++ b/internal/checker/checker.go
@@ -13892,7 +13892,7 @@ func (c *Checker) checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(nod
diagnostics.X_0_was_imported_here)
// TODO: how to get name for export *?
name := "*"
- if !ast.IsExportDeclaration(typeOnlyDeclaration) {
+ if typeOnlyDeclaration.Kind != ast.KindExportSpecifier && !ast.IsExportDeclaration(typeOnlyDeclaration) {
name = getNameFromImportDeclaration(typeOnlyDeclaration).Text()
}
c.error(decl.ModuleReference, message).AddRelatedInfo(createDiagnosticForNode(typeOnlyDeclaration, relatedMessage, name))Is there a crasher that minimizes further so we could write a test?
Here's a short repro:
// @filename: t.ts
import a = require("./a");
import foo = a.Foo; // Causes crash
// @filename: a.ts
type Foo = { x: number }
export type { Foo };Issue is that getNameFromImportDeclaration should also be able to get names from export declarations and specifiers. It's an easy fix, I'll put up a PR.
Actually, getNameFromImportDeclaration should just go away. We can just use the Node.Name() method.