Repository navigation
feat(layout): 未定型整数字面量按上下文适配(行为变更) - #628
Merged
Merged
Conversation
无符号变量或 cast 与未定型整数字面量运算(如 uint64(5) + 1、uint8(5) + 1) 此前 init 失败;现按上下文把字面量适配到另一侧类型后再判,正常计算。 字面量放不进目标类型时按自然类型处理,随后落入混合符号报错; 两侧都是确定类型且符号冲突的(uint64_var + int64_var)行为不变,仍报错。 新增 layout/tests/uint_literal_adapt.rs(7 例)。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
⚠ 行为变更
变的是
uint64(5) + 1、uint8(5) + 1这类「无符号变量或 cast + 未定型整数字面量」,从 init 失败变为正常计算。
不变的是
两侧都是确定类型且符号冲突的(如
uint64_var + int64_var)仍然报错,行为不变。为什么值得单独一个 PR
u + 1是最常见的写法之一,以前会在布局期就失败——这不是边缘情况,而是无符号类型日常不可用的主因。
读者看到「⚠ 行为变更」时容易以为又是一次破坏性改动;这里恰恰相反:它修的是
「本来就不该失败的东西」。
规范依据
落地的条款是:
03-类型系统/01-种类与定宽类型第 10 条(未定型整数字面量例外);05-runtime语义/11-指令派发与特化的补充条款「未定型整数字面量不计入int × uint混合符号判定」。
两条已在 #625 / #626 合入,本 PR 是执行侧实现,PR 与规范可互相追溯。
证据分工(重要:两类证据不是同一件事)
uint_literal_adapt.rs)diff=0不能被当成「已验证」。新行为正确性只由那 7 例支撑,其中两条正好覆盖边界:confirmed_mixed_signs_stay_untyped—— 两侧确定类型仍不特化(行为不变的那条)uint8_literal_boundary_fits_and_overflows—— 越界字面量按自然类型处理,随后落入混合符号报错验证(
git archive干净副本,layout + runtimec2 + byteseek 三重建)09-debugger/pauses.kv)文件(3 个)
关联 #622,不关闭该 issue。
🤖 Generated with Claude Code