Issue #2623: A Vec[String]? whose items are text views is refused (NK1104), though a Vec[String] is accepted

Open and answer this issue on GitHub.

ready · opened 2026-11-21 · updated 2026-11-21 · 0 comments

Found while building the TOML reader for the compiler (#2602), optional list fields. Area: checker (text tiers).

Probe (target/fast/nikaia run l4.nika)

fn parts(t: String) -> Vec[String] {
	return t.split(",").collect()
}
fn some_parts(t: String) -> Vec[String]? {
	let v = parts(t)
	return v
}
fn main() throws {
	let t = "x,y"
	println(f"{some_parts(t)?.len() ?? 0}")
}

Prints:

error[NK1104]: You're returning a `Vec[String]` whose items are views, but the function is declared to return `Vec[String]?`.
  --> l4.nika:6:9
 6 | 	return v

The same in a grammar rule, rule R -> Vec[String] = "[" xs:list(S, ",") "]" -> { xs } read by entry rule read -> Vec[String]? = v:R eof -> { v }, gives error[NK1104]: This action builds a Vec[String] whose items are views, but its rule returns Vec[String]?. So a grammar cannot fill a Vec[String]? field.

Expected

It compiles and prints 2. ADR-282 D12 decides per position whether text is owned or a view. fn parts returning Vec[String] is accepted, and T? holds the same T, so its item tier should be followed through the ?.

Cause (traced)

container_of in crates/nikaia-std/src/compiler/tiers.nika:121 returns null for a nullable type (if ty.is_view || ty.is_nullable || ty.is_tuple || ty.code != null { return null }), so a Vec[String]? position is never given an item tier, and the view items do not fit it.

To build

  1. In tiers.nika, follow a nullable container to its inner type, as for the plain one (for Vec[...]? and map types with ?).
  2. Add test tests/compiler/tests/an_optional_list_of_text_views.nika: the probe, with .stdout 2. Add a second shape too: a grammar entry rule returning Vec[String]?.

Done when

Both shapes run and print under --both-settings.

Back to Open Issues