Why would a "using terms" script fail if I add `use framework "Foundation"`?

My app iClip loads a specially named script (“iClip Events.scpt”) and then invokes handlers in it, e.g. to filter incoming data.

Now, when I tried to add some advanced features to the script, and I also had to include an ObjC framework for it, the script suddenly cannot access the app’s properties any more:

Screen Shot 2023-04-14 at 21.46.28

Here’s the code:

use framework "Foundation"

using terms from application "iClip"
	
	on init
	end init
	
	on quit
	end quit
	
	on clip set switched
	end clip set switched
	
	on filter incoming flavors
		get current clipping
	end filter incoming flavors
	
	on clipping added by recorder
	end clipping added by recorder
	
	on clipping added interactively
	end clipping added interactively
	
end using terms from

If I remove the “use” line at the top, the error goes way.

Also, when I use the “current clipping” from a normal script, then it’s not a problem either (it’ll give a “missing value” but without giving an AS error or throwing an exception:

use framework "Foundation"

tell application "iClip"
	get current clipping
end tell

So it only occurs with the using terms handlers.

What could be causing this?

try adding this after the “use framework” line

use scripting additions

I had already. Made no difference

Nor does this:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

What happens if you comment out the init handler?

I can’t remove the “init” handler easily because it’s part of the required terminology (for testing I could build one with a renamed handler, but that’s a bit of work and I can’t get rid of it now easily any more, as it’s already used by existing scripts).

However, I found out what makes it work: I have to add its inside the handler, like this:

get its current clipping