Gradual map domain with `none` looses static part when computing lower bound

已关闭
#15,854 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@lukaszsamson 已经在做这个了。

开始于 2026年9月5日。

  • #15855 来自 @lukaszsamson —— 未关闭

评估

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

调研方向

从复现中使用的 Module.Types.Descr 入口点开始:lower_bound/1、upper_bound/1 以及 map 域处理。运行提供的示例,以确认渐进式 map 和逆变函数参数会丢失静态部分。当所示比较结果相等且没有精度损失时,即表示完成。

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

描述

Existing issue
  • I have searched existing issues and could not find a duplicate.
Elixir and Erlang/OTP versions

1.21.0-dev@87af1e34e

Operating system

any

Current behavior

Map domain entries are documented to be implicitly optional - a domain value none() means that the map contains no entries whose keys belong to that domain. It does not make the entire map type empty yet the current implementation breaks this assumption and loses precision of the static part:

Repro:

import Module.Types.Descr

static =
  closed_map([
    {[:integer], none()},
    {:b, {integer(), false}}
  ])

gradual =
  closed_map([
    {[:integer], dynamic()},
    {:b, {integer(), false}}
  ])

IO.puts("actual:   #{to_quoted_string(lower_bound(gradual))}")
IO.puts("expected: #{to_quoted_string(static)}")
IO.inspect(lower_bound(gradual) == static, label: "equal?")

result:

actual:   none()
expected: %{integer() => not_set(), b: integer()}
equal?: false

The same static part loss through contravariant argument handling

actual_fun = upper_bound(fun([gradual], atom()))
expected_fun = fun([static], atom())

IO.puts("actual fun:   #{to_quoted_string(actual_fun)}")
IO.puts("expected fun: #{to_quoted_string(expected_fun)}")
IO.inspect(actual_fun == expected_fun, label: "fun equal?")

result:

actual fun:   (none() -> atom())
expected fun: (%{integer() => not_set(), b: integer()} -> atom())
fun equal?: false

Another example

static =
  open_map([
    {[:tuple], none()},
    {:b, {integer(), true}}
  ])

gradual =
  open_map([
    {[:tuple], none()},
    {:b, {opt_union(integer(), dynamic(float())), true}}
  ])

IO.inspect(lower_bound(gradual) == static)
# Current: false
# Expected: true
Expected behavior

No precision loss

主要语言
Elixir
星标
26.7k
派生
3.7k
平均合并
10 小时
30 天内合并 PR
47

环境准备

从这里开始

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

elixir-lang/elixir 的其他 Issue

查看 elixir-lang/elixir 的全部 Issue

相似的 Issue

更多 Elixir Issue

把新 issue 发到你的邮箱

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