Why doesn't it swear at overlay during assembly?

Good afternoon, everyone! I made a typo and didn't add a dot before the overlay and got a crash while the application was running. There was no useful information in the crash stack to find the problem spot. But over time I realized that the mistake was that I forgot to add a dot. And here's the question: If the code falls without a dot and it seems to be initially incorrect, then why didn't the compiler report an error during assembly?

struct ContentView: View {
    var body: some View {
        Text("Text 1")
        overlay(Text("Text 2"))
    }
}

Compiler does not guess it is a modifier.

It could well be a func you have defined.

As in the following (I changed to overlap, otherwise it crashes also):

func overlap(_ aView: any View) -> some View {
    return Text("Text 2")
}

struct ContentView: View {
    var body: some View {
        Text("Text 1")
        overlap(Text("Text 2"))
    }
}

The problem is that it is resolved at runtime, not at compile time. And at runtime, it cannot find the overlay func, hence the crash.

Same occurs if, for instance, you miss to define an environment var. It will crash at runtime but compile fine.

This article can shed some light on it, and somewhat of a fix: https://www.hackingwithswift.com/quick-start/swiftui/how-to-make-swiftui-modifiers-safer-to-use-with-warn-unqualified-access.

It is not impossible, but this not how SwifUI works (as far as I understand).

If that may help, as explained here, https://serialcoder.dev/text-tutorials/swiftui/does-swiftui-view-not-compile-time-to-start-making-it-lighter/

SwiftUI views are not real views, rather configurable “descriptions” that are being rendered into actual views later. All these “descriptions” are expressions that the compiler evaluates.

In simple words, compiler finds there is an overlay defined somewhere, with the right arguments, so it can evaluate. But at runtime, when it tries to match, it crashes with an error reported at main: Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ff7b9560fd8)

Why doesn't it swear at overlay during assembly?
 
 
Q