This does compile, but I would have expected it to have the
same compile error as the above code:
alias (path to startup disk as text) & "this file does not exist"
How come?
That's a very clever design. When compiling an alias, the
appleScript compiler tries to resolve an alias, and if the item is
not present, it returns an error.
However, in order to resolve the alias, the compiler will no
execute any script or command.
This allows us to aliases with variables and other commands that
don't exist at compile time, but will exist at runtime.
In your example, "path to" is a command (standard editions) and
since the compiler doesn't execute command it can't complete the
path so it allows the alias to remain unresolved.
It's the same mechanism that allows the following to compile:
set myFile to alias choose file
or
set myFile to chooseFile
alias myFile
And this fails:
class of alias ((path to startup disk as text) & "this file does
not exist")