Silver: is and as? operator does work with extensions of base

(Taras Vozniuk) #1

IDE: Fire
Target (If relevant): Java

After extending and making it comply to protocol is and as? operators will fail to identify the instance as being of type
When creating my own class, extending, and making it comply to the very same protocol, works fine.

Compiler generated extension subclass:

entity: lakestonecore.tests.__Extension_File$Duck_File_AnyFileOrDirectory

code (TestDirectory.swift):

for entity in testDirectory.filesAndSubdirectories {
	if entity.isDirectory {
		Assert.IsTrue(entity is Directory)
	} else {
                 //fails here
		//Assert.IsTrue(entity is File)

Actual code can be found here:

(Carlo Kok) #2

We’ve got some ideas on how to solve this in a limited way, ie if you have the interfaces it can allow casting back, but it won’t work as say Object -> File when originating as a AnyFileOrDrecitory.

(RemObjects) #3

Thanks, logged as bugs://76302

(Taras Vozniuk) #4

Yeah, right. It’s not a big deal, I only intented using is type check for this API in unit test case, but overall I guess it might be more or less common issue.

(RemObjects) #5

bugs://76302 got closed with status fixed.

(Carlo Kok) #6

So this works (well partially); when you have a File and cast it to AnyFileOrDirectory (which is an extension) it works, is works too. When you have an Object/Any containing a File it won’t work unfortunately, that’s a runtime limitation.