metagen: processDerivedClassRefs converts ancestor methods to properties using subclass selectors (phantom accessors in emitted metadata)

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp, objective-c
领域
tooling

调研方向

Start in metadata-generator/src/IR/Class.cpp with processDerivedClassRefs, which calls convertMethodToPropertyIfNeeded in the wrong direction, and trace how ClassDecl::postProcessMembers invokes it. Confirm that an ancestor method record can be rewritten with a descendant's getter and setter selectors. Done means the ancestor keeps its own method record, such as NSView.autoscroll not gaining isAutoscroll, while superclass-to-subclass property propagation still works.

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

描述

Summary

processDerivedClassRefs in metadata-generator/src/IR/Class.cpp calls convertMethodToPropertyIfNeeded in the wrong direction: it rewrites an ancestor class's method record into a property using the derived class's getter/setter selectors. Generated metadata then declares members on classes that never implement those selectors.

ClassDecl::postProcessMembers iterates members of a class, then runs processDerivedClassRefs(member, derivedClassRefs), which invokes convertMethodToPropertyIfNeeded(member /* ancestor member */, cls->getMemberNamed(member.name) /* derived member */, false). Inside, when memberInSuperclass->kind == kMemberProperty — i.e. the derived class declared a property — the ancestor's method is converted to a property that copies memberInSuperclass->getterSelector/setterSelector, selectors that belong to the subclass and that the ancestor does not implement.

Observed in metadata.macos.arm64.nsmd (generated for the macosx SDK): a census found 213 phantom getters and 212 phantom setters. Example: NSView.autoscroll/NSClipView.autoscroll carry NSMatrix's isAutoscroll/setAutoscroll: — messaging a stock NSView with isAutoscroll raises -[NSView isAutoscroll]: unrecognized selector sent to instance.

Expected

A derived class's member declarations should not mutate the ancestor's member record; the property conversion should only flow superclass → subclass (which the postProcessMembers superclass walk already handles). Either drop the processDerivedClassRefs conversion or scope it so an ancestor never borrows a descendant's selectors.

Environment

  • NativeScript/runtimes main (verified identical at 5b697b39)
  • metadata-generator source + generated metadata.macos.*.nsmd
  • Impact is multiplied by the napi backend's unguarded selector dispatch — reading any phantom member aborts the process instead of raising a JS error (filed separately).
主要语言
C++
星标
27
派生
4
平均合并
5 天 11 小时
30 天内合并 PR
12

环境准备

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

从这里开始

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

NativeScript/runtimes 的其他 Issue

查看 NativeScript/runtimes 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

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