If you remove the explicit typing on params they default to 'dynamic' which eventually become Object in the C# source code
I'd venture the failure messages for the compile refers to inability to convert 'Object' types to 'String' or int in passing the now dynamic params into the baseclass initializer.
(It would help immensely for 'compilation fails' type questions if you posted the error message.)
For it to work the types of the params on the methods need to match or be convertible ( i,e the baseclass needs to take a dynamic (unspecified arg Type as well and the type used is resolved at runtime)
This isnt type inference as such more typing compatibility across methods as you've explicitly specified the types on the initializers.
i.e This fails due difference in Types fro the baseclass initialiser and its call from the subclass
- Code: Select all
class Shape is abstract
var _myId as String
cue init(s as String)
base.init
.id = s
pro id as String
get
return _myId
set
_myId = value
pro area as float is abstract
get
def toString as String is override
return .id + " Area = " + String.format("{0:F2}", .area)
class Square inherits Shape
var _mySide as int
cue init(side, id )
base.init(id)
_mySide = side
pro area as float is override
"""Given the side, return the area of the square."""
get
return _mySide * _mySide
def main is shared
pass
with
- Code: Select all
TypeInfer.cobra(24): error: The best overloaded method match for "Shape.Shape(string)" has some invalid arguments (C#)
TypeInfer.cobra(24): error: Argument "1": cannot convert from "object" to "string" (C#)
Compilation failed - 2 errors, 0 warnings
This succeeds (base initialiser and subclass call both same (unspecified,dynamic) type
- Code: Select all
class Shape is abstract
var _myId as String
cue init(s)
base.init
.id = s
pro id as String
get
return _myId
set
_myId = value
pro area as float is abstract
get
def toString as String is override
return .id + " Area = " + String.format("{0:F2}", .area)
class Square inherits Shape
var _mySide as int
cue init(side, id )
base.init(id)
_mySide = side
pro area as float is override
"""Given the side, return the area of the square."""
get
return _mySide * _mySide
def main is shared
pass
Type inference in itself is relatively simple - if you are creating a variable and its not already typed it'll take the type of its assignment expression (rvalue type) but you need to realise that the variable
still ends up staticly typed ( inferred not explicitly set)
Dynamic types confuse this some as a dynamic type sez that the variable type can be anything and change depending on whats assigned to it.
BUT as this gets converted to C# ( statically typed language currently) the implementation type for 'dynamic' is Object which means that you can make programs that compile fine wrt Cobra
but that the C# compiler balks at (mostly around implicit conversions from Object to some other type).
For classes I find this usually means that you either want to explicitly type all the params and vars (except where you definitely want a type morphing value - rare SFAICT) OR you leave all (most) of the values as dynamic and let them get the types from their construction/assignment types. Its arbitrary mixtures that cause problems especially up inheritance (method) chains.
I'd expect most of the issues with this are back end compiler specifics wrt what it allows with casting Object to