attempts to retain current casting behavior
add test (see #1810)
add some stack overflow detection (see #1757)