paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Highly illogical, Kirk: spotting type mismatches in the large despite broken contracts, unsound types, and too many linters

极不合逻辑,Kirk:即便契约破损、类型不健全且 linter 过多,也能大规模发现类型不匹配
OOPSLA 6(OOPSLA2)2022匹配度 3/10 · 论文关注 TypeScript 类型声明与 JavaScript 代码不匹配的检测,属于程序语言、类型系统与测试交叉的工作,但与用户画像核心的 PL↔AI、浮点程序分析、贝叶斯程序分析等方向没有直接关联。其工程落地和维护视角有一定参考价值,但不涉及 LLM/Agent 或形式化验证与 AI 的结合。引用 5 inbox
Joshua Hoeflich, Robert Bruce Findler, Manuel Serrano
crossref: 2026-09-10

AI 速览

一句话:提出 Scotty,将 DefinitelyTyped 的类型声明转为契约并绑定到库与测试套件边界,通过运行测试检测类型与 JavaScript 代码的不匹配。

DefinitelyTyped 为数千个 JS 库提供类型声明,但类型与代码无形式化关联,且随时间容易失配。本文提出 Scotty:将每个包的类型转为契约,装在库与测试套件边界上,运行测试即可暴露类型与 JavaScript 代码的不匹配。该工具强调自动化与通用性,主动牺牲完备性以避免假阳性。Scotty 能处理 DefinitelyTyped 上 8006 个包中的约 26%(代码可用且测试通过的包中占 61%),揭示大量错误并促成 100 个被接受的修复 PR,证明该思路对长期维护的价值。作者还总结了 JavaScript 生态中语言语义之外因素的重要性,并发现程序员有时偏好错误类型,为 TypeScript 改进提供了方向。

问题
如何在大规模 JavaScript 生态中,检测并持续防止 DefinitelyTyped 类型声明与实现代码之间的不匹配,尽管类型与代码无形式化关联且类型本身可能不健全。
方法
把每个包的类型声明转换为契约并安装在库与测试套件边界上,运行测试套件以暴露类型与 JS 代码的不一致;有意牺牲完备性以避免假阳性。
评估
在 DefinitelyTyped 的 8006 个包上运行,能处理约 26%(在代码可用且测试通过的包中占 61%),发现大量错误并产生 100 个被接受的修复 PR。
原文摘要(Abstract)

The DefinitelyTyped repository hosts type declarations for thousands of JavaScript libraries. Given the lack of formal connection between the types and the corresponding code, a natural question is are the types right? An equally important question, as DefinitelyTyped and the libraries it supports change over time, is how can we keep the types from becoming wrong? In this paper we offer Scotty, a tool that detects mismatches between the types and code in the Definitely-Typed repository. More specifically, Scotty checks each package by converting its types into contracts and installing the contracts on the boundary between the library and its test suite. Running the test suite in this environment can reveal mismatches between the types and the JavaScript code. As automation and generality are both essential if such a tool is going to remain useful in the long term, we focus on techniques that sacrifice completeness, instead preferring to avoid false positives. Scotty currently handles about 26% of the 8006 packages on DefinitelyTyped (61% of the packages whose code is available and whose test suite passes). Perhaps unsurprisingly, running the tests with these contracts in place revealed many errors in Definitely-Typed. More surprisingly, despite the inherent limitations of the techniques we use, this exercise led to one hundred accepted pull requests that fix errors in DefinitelyTyped, demonstrating the value of this approach for the long-term maintenance of DefinitelyTyped. It also revealed a number of lessons about working in the JavaScript ecosystem and how details beyond the semantics of the language can be surprisingly important. Best of all, it also revealed a few places where programmers preferred incorrect types, suggesting some avenues of research to improve TypeScript.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot1421,
  title = {Highly illogical, Kirk: spotting type mismatches in the large despite broken contracts, unsound types, and too many linters},
  author = {Joshua Hoeflich and Robert Bruce Findler and Manuel Serrano},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {6},
  number = {OOPSLA2},
  year = {2022},
  doi = {10.1145/3563305}
}