fix(checker): build a literal of a non-default List or Map implementation through From #345
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/212-concrete-list-literal"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #212
A list or map literal annotated with a concrete implementation other than the default one is now built through the target's own
From<Iterate<...>>, as the refine comment decided:const r: RingList<Int> = [1, 2],var r: RingList<Int> = [],const t: TrieList<Int> = [1, 2]andconst m: HashMap<String, Int> = ["a": 1]are recorded asFromIteratewith the annotation as their type.ArrayListandTrieMapannotations stayDefault; trait-typed literals (List<Int>,Iterate<Int>,Show) are unchanged.Item; aList/Mapimplementation that is notFromgets the "cannot become" diagnostic (tested with a small userMaptype).Lowering scope (beyond the checker): the refine assumed
ArrayList<Int> = [1, 2]already lowered asDefault. It did not:boundsOfLiteralhas no trait bound for a nominal type, soArrayList<Int> = [1, 2]andTrieMap<String, Int> = ["a": 1]both failed with "a list/map literal of a type that is not aList/Mapis not supported" (reproduced with the nightly). This PR therefore also touchescompiler/src/ir/lower/collection.trb:ArrayList/TrieMapannotation is filled directly into the destination (lowerDirectList,filledMapwith a given slot);FromIteratetarget is a concrete type is built as aTrieMap, coerced toIterate<(Key, Value)>and handed toTarget.from(lowerBuiltMap); the list side already hadlowerBuiltList.Because
compiler/src/irchanges, gates a and b apply.Tests:
compiler/tests/collections.test.trb(TrieList, empty literal, item mismatch, TrieMap default, userMapwith and withoutFrom); conformancering-list.trbnow usesconst literal: RingList<String> = ["a", "b"](same.expected), andliteral-through-from.trbgainsHashMap,RingList,ArrayListandTrieMapliterals. The.allocationsbudget ofliteral-through-fromwill move and is taken from CI.Docs:
docs/TYPECHECKER.md(the three shapes),docs/design/COLLECTIONS.mdC7 (known gap closed),docs/ROADMAP.md(collections row). Noskills/regeneration needed.bb6a1ae3b5040013103dNew head: the PR is now at
0400131(review was requested forbb6a1ae, which is no longer part of the PR). CI for0400131is still running; request review again if the gateway does not re-trigger it.040013103d66ab611d66const r: RingList<Int> = [1, 2]) #212Review of
66ab611(CI combined status: success, incl. tier A/B, bootstrap, gates, pdisc).Non-blocking: none.
const r: RingList<Int> = [1, 2]) #212