Abstract methods block coverage and direct calls when no subclass exists

未关闭
#3,077 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@alantriesagain 已经在做这个了。

开始于 2026年11月6日。

  • #3082 来自 @alantriesagain —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
typescript
领域
compilers

调研方向

Start by reading the compiler paths that handle abstract method declarations, untyped property lookup, and direct calls; the issue gives reproductions but names no source files or tests. Compare the two examples with Node and inspect the existing SC1090 handling. Done means coverage treats abstract declarations as having no runtime value and direct calls match Node’s receiver, argument, and TypeError behavior. A linked pull request is already open.

由索引模型根据 Issue 内容生成。

描述

Abstract methods block coverage and direct calls when no subclass exists

The compiler refuses or defers abstract methods in two shapes that JavaScript handles.

Untyped lookup

A value held as any whose instances reach o[k] gets a branch per class and member. For an abstract method, the branch asks for the method's value, which an abstract declaration does not have. Every such branch is deferred with SC1090 values of abstract method declarations. The program runs and matches Node, but coverage never reports it as fully static.

abstract class Holder {
  abstract current(): string;
}

class Impl extends Holder {
  current(): string {
    return "ok";
  }
}

const read = (o: any, k: string) => o[k];
const impl: Holder = new Impl();
console.log(read(impl, "current"), impl.current());

On 0.4.8, scriptc coverage of the larger form in our corpus (abstract-methods-untyped-lookup.ts) reports 6 deferred sites. The same failure reproduces on main (979a65246).

Direct call

A concrete method that calls an abstract method with no concrete implementation below the receiver's static class is refused at build time, even when the program never subclasses the class. tsc makes every instantiable subclass implement the method, so no instance can reach the call.

abstract class Source {
  abstract count(): number;

  liveFrom(): number {
    return this.count();
  }
}

class Shelf {
  source: Source | null = null;
}

const shelf = new Shelf();
console.log(shelf.source === null ? "none" : shelf.source.liveFrom());

Node prints none. On 0.4.8, the build fails with SC1090 calls of the abstract method 'count' with no concrete implementation below the receiver's static class.

An abstract declaration has no value at run time. An untyped lookup should select the implementation of the constructible subclass the instance belongs to, nearest first, and read undefined when no class below the receiver implements it. A direct call should evaluate its receiver and arguments, then throw Node's TypeError, <callee> is not a function.

I opened #TBD with a patch that implements both behaviors.

主要语言
TypeScript
星标
6.5k
派生
212
平均合并
13 小时 6 分钟
30 天内合并 PR
799

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

vercel-labs/scriptc 的其他 Issue

查看 vercel-labs/scriptc 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。