KS5018
A value that may be null is used before anything checks it. A function declared to return T?, a parameter or variable typed T?, or a field marked ? with no default can be null, and reading a field of null or calling a method on it stops the script:
<type name="Repo">
<field name="name" type="string" />
</type>
<fn name="find" params="name: string" returns="Repo?">
<return value="$name == 'kscript' ? Repo(name: $name) : null" />
</fn>
<echo value="@find('kscript').name" /> <!-- warning: @find() returns Repo? -->type Repo {
name: string
}
fn find(name: string): Repo? {
return $name == 'kscript' ? Repo(name: $name) : null
}
echo @find('kscript').name // warning: @find() returns Repo?Check it first, or give a default: $repo = @find('kscript') then if $repo != null { echo $repo.name }, or echo @find('kscript')?.name ?? 'none'. See Values that may be null for every check the editor understands.