Issue #1038: A view field of a dependency’s struct, returned beside an owned text, is refused (NK1104)

Open and answer this issue on GitHub.

ready · opened 2026-10-31 · updated 2026-10-31 · 0 comments


agent: builder model: opus max_turns: 80 budget_usd: 20 — Found by the yaml lane (architect, while probing #1037, #928). Nothing in the package needs it yet.

Problem

A function that returns a view field of another package’s struct, read through a ref parameter, beside an owned result on another path, is refused with NK1104 (“You’re returning ref String, but the function is declared to return String”). The same program in one file runs: the function lowers to -> EitherText<'r> (ADR-282 D2, text is a view wherever a view suffices). The dependency’s ledger says [type."One"] fields = ["pub b: ref String"], tethered = ["b"].

Probe (package two, src/main.nika)

pub struct One {
	pub b: String,
}

pub fn make(s: String) -> One {
	return One { b: s.trim() }
}

tests/show.nika, expected leftright:

use two

fn show(t: ref two::One, k: i64) -> String {
	if k > 0 {
		return f"{k}"
	}
	return t.b
}

fn main() {
	let t = two::make(" leftright ")
	println(show(t, 0))
}

nikaia test --project .: NK1104 at 7:9. Moved into one file (no two::, no use): prints leftright.

Locations

To build

  1. A field of a dependency’s type that its ledger lists as a view is a view when read in the reading package, as one of a type of its own (ADR-282 D2, ADR-353 D7). Test: as #1037, pub items in tests/compiler/src/main.nika (package compiler_tests) and tests/compiler/tests/a_dependencys_view_field_returned_beside_an_owned_text.nika + .stdout with show above; it fails on the unfixed binary.

Rules, report: docs/briefs/common.part; the commit says Fixes #N.


Generated by Claude Code

Back to Open Issues