Hi all. First post here. I did some stuff with TADS2 ages ago and I’m trying to get into TADS3 now.
Here is my problem:
I have an object of type Container.
I am trying to iterate over its contents and put some of them elsewhere.
The code snippet is like this:
foreach( local c in innerContainer.contents )
if( /* – complex check here that’s not relevant to this question – */ )
c.basicMoveInto( self );
(Before you chastise me for using basicMoveInto instead of moveInto, I have a very good reason for this. I’m doing it because this occurs inside a “notifyRemove” method, which I don’t want to re-trigger and cause a regressive recursion.)
The problem happens on that statement “c.basicMoveInto(self)”. If I compile with all the warnings enabled, and the “treat warnings as errors” enabled, which I definitely want to do, I get this warning and can’t compile:
warning: undefined symbol “basicMoveInto” - assuming this is a property name
Now, I know exactly why this is happening, but I don’t know how to fix it other than to turn off treating warnings as errors, which is not a good idea. It’s happening because TADS3 is only strongly typed at runtime and not at compile time, so until runtime it doesn’t realize that the variable ‘c’ is only ever going to be holding objects of type Thing or subclasses of Thing. It thinks that ‘c’, being taken from the contents which is a List type, could be literally any language object, not necessarily a Thing or subclass of Thing. I know it can only be a Thing because it’s taken from the list of contents of a Container, so I know this is a safe assumption to assume it has a basicMoveInto(), but the compiler doesn’t know that, so I get the warning.
How do I make the warning go away without dangerously making ALL warnings go away? I don’t think there is such a thing as “casting” in TADS3, so that’s not the answer. I can’t declare C to be of type Thing (can I?). All variables are untyped at compile time.
There are times when the “assuming this is a property name” has been a very important warning that let me discover I was misspelling something, so I don’t want to suppress it universally - just in this one case.