bcc icon indicating copy to clipboard operation
bcc copied to clipboard

Module scoped objects with 'New'

Open davecamp opened this issue 3 years ago • 3 comments

Is module scope taken into account with respect to Types within modules? It works Ok for Global variables - Ie If a Global variable is in a module and a Global variable is in the main code file you can resolve module resolution by:

SuperStrict
Global Variable:Int = 20
Print (Some.Module.Variable) ' Print the value of a global that is defined in the mentioned module
Print (Variable)             ' Print the value of the global in this file

There appears to be an issue when doing the same for Types

SuperStrict

Type Foo
	Field Bar:Float
EndType

' any valid module name can be used here - even if Foo isn't inside it
Local Test:Foo = New Some.Module.Foo    ' Some.Module can be exchanged for any valid module name

There are a couple of things kind of expected to happen with that last code.

  1. There is no type in Some.Module.Foo so an error is expected to say this.
  2. If the module did have a Type called Foo within it then the module version is ignored.
  3. Trying to cast from the Some.Module.Foo to the local type of Foo should produce an error.
  4. If module scoped resolution for types isn't allowed then a general error would be produced in regards to a duplicate type.

The code above compiles and runs creating an instance of Foo using the local version.

davecamp avatar Feb 09 '22 08:02 davecamp