Commit 5d57abfb

5d57abfbfd1dMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 1 file · +1 added

Description

Add safe navigation operator (&.) support

The &. operator works transparently in Spinel's monomorphic AOT code since Prism parses it as a regular PM_CALL_NODE with SAFE_NAVIGATION flag. In statically typed code, the receiver type is always known at compile time, so no nil guard is needed.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
5d57abfbfd1d
Parent
5aa336d6ea70

examples/bm_safe_nav.rbaddedView file

1+# Test safe navigation operator &.
2+
3+s = "hello"
4+puts s&.length # 5
5+puts s&.upcase # HELLO
6+
7+arr = Array.new
8+arr.push(10)
9+arr.push(20)
10+puts arr&.length # 2
11+
12+# Chain
13+puts "world"&.upcase&.length # 5
14+
15+puts "done"