Skip to content

Fix List.Add() returning the list without the added value - #80

Merged
siimav merged 1 commit into
KSP-RO:masterfrom
celino:fix-list-add
Oct 15, 2026
Merged

siimav merged 1 commit into
KSP-RO:masterfrom
celino:fix-list-add

Conversation

@celino

@celino celino commented Sep 30, 2026

Copy link
Copy Markdown

Add() on a list never adds anything:

(l, v) => { if (l == null) { l = new List<T>(); } l.ToList().Add(v); return l; }

ToList() makes a copy, the value goes into the copy, and the original list is returned. So [Kerbin].Add(Mun) is still [Kerbin], and Add on a null list returns an empty list. This changes it to copy first and then add, the same way Exclude right below it works, so the input list is still left untouched.

I ran into it through RoverScience's rover contract, which relies on Add() (linuxgurugamer/RoverScience-Continued#11). The pattern also shows up in test/Expression.cfg ([Kerbin].Concat([Mun]).Add(Minmus).Random()), where Minmus can never be picked.

Tested the old and new lambda in isolation: [Kerbin].Add(Mun) gave [Kerbin] before and [Kerbin, Mun] after. The patched build loads in KSP 1.12.5 with about 330 contract types from several packs and no errors. In game, a test contract group with [Kerbin].Add(Mun) shows a count of 2 in the debug window (Alt+F10).

@celino

celino commented Oct 14, 2026

Copy link
Copy Markdown
Author

Hi @siimav, a gentle bump, and a short summary in case it's easier to look at the four together. No rush at all.

They don't touch the same files, so they can be merged in any order. I've also been playing my own career with all four on top of master, with no Contract Configurator errors in the log so far.

If you'd rather have any of them changed, split or squashed, just let me know.

@siimav
siimav merged commit f22151f into KSP-RO:master Oct 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants