Assertion failure at Python/instruction_sequence.c:121: `int _PyInstructionSequence_Addop(instr_sequence *, int, int, location): Assertion 'OPCODE_HAS_ARG(opcode) || HAS_TARGET(opcode) || oparg == 0' failed`
未关闭
还没有人认领这个 Issue。
interpreter-core
tests
type-crash
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Crash report
What happened?
import unittest
from test.support.bytecode_helper import CodegenTestCase
class IsolatedCodeGenTests(CodegenTestCase):
def assertInstructionsMatch_recursive(self, insts, expected_insts):
self.assertInstructionsMatch(insts, expected_insts)
def codegen_test(self, snippet, expected_insts):
import ast
a = ast.parse(snippet, 'my_file.py', 'exec')
insts = self.generate_code(a)
self.assertInstructionsMatch_recursive(insts, expected_insts)
def test_if_expression(self):
snippet = '42 if True else 24'
expected = [('RESUME', 0, 0), ('ANNOTATIONS_PLACEHOLDER', None), ('LOAD_CONST', 0, 1), ('TO_BOOL', 256, 1), ('POP_JUMP_IF_FALSE', (false_lbl := 1), 1), ('LOAD_CONST', 1, 1), ('\x00', (exit_lbl := self.Label())), false_lbl, ('', 255, 1), exit_lbl, ('POP_TOP', None), ('LOAD_CONST', 1), ('RETURN_VALUE', None)]
self.codegen_test(snippet, expected)
if __name__ == "__main__":
unittest.main(verbosity=0)
python: ../Python/instruction_sequence.c:121: int _PyInstructionSequence_Addop(instr_sequence *, int, int, location): Assertion `OPCODE_HAS_ARG(opcode) || HAS_TARGET(opcode) || oparg == 0' failed.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Python/instruction_sequence.c:121 的 assertion 开始,通过 CodegenTestCase.generate_code() 使用提供的 IsolatedCodeGenTests 片段重现它。跟踪为条件表达式生成的指令,并确定为什么会以报告的 opcode 和 argument 到达该 assertion。完成标准是 reproducer 不再 abort,并且有一个 regression test 覆盖此情况。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 30/100