blitz-research/monkey2

C++ compiler build error when Interface implementation is wrong

Opened this issue · 2 comments

In the following code the implementation of 'MyMethod:String' in class 'Test' does not match the signature of 'MyMethod:Bool" in the interface 'MyInterface':

Interface MyInterface
    Method MyMethod:Bool()
End

Class Test Implements MyInterface
    Method MyMethod:String()
        Return "string"
    End
End

Function Main()
    New Test
End

I get a c++ build error:

Parsing...
Semanting...
Translating...
Compiling...
Build error: System command failed:

g++ -c -std=c++14 -mmacosx-version-min=10.9 -Wno-deprecated-declarations -Wno-tautological-pointer-compare -Wno-undefined-bool-conversion -Wno-int-to-void-pointer-cast -Wno-inconsistent-missing-override -Wno-logical-op-parentheses -Wno-parentheses-equality -O3 -DNDEBUG -I"/Users/danilo/Monkey/monkey2/modules/" -I"/Users/danilo/Monkey/monkey2/modules/monkey/native" -I"/Users/danilo/Monkey/monkey2/tmp/" -DNDEBUG=1 -DBB_THREADS=1 -I"/Users/danilo/Monkey/monkey2/tmp/untitled10.buildv1.1.15/macos_release_mx/build/" -MMD -MF"/Users/danilo/Monkey/monkey2/tmp/untitled10.buildv1.1.15/macos_release_mx/build/r5b58089e.cpp_r.deps" -o "/Users/danilo/Monkey/monkey2/tmp/untitled10.buildv1.1.15/macos_release_mx/build/r5b58089e.cpp_r.o" "/Users/danilo/Monkey/monkey2/tmp/untitled10.buildv1.1.15/macos_release_mx/include/_r.cpp"

In file included from /Users/danilo/Monkey/monkey2/tmp/untitled10.buildv1.1.15/macos_release_mx/include/_r.cpp:9:
/Users/danilo/Monkey/monkey2/tmp/untitled10.buildv1.1.15/macos_release_mx/include/untitled10_untitled10.h:32:12: error: virtual function 'm_MyMethod' has a different return type ('bbString') than the function it overrides (which has return type 'bbBool' (aka 'bool'))
  bbString m_MyMethod();
  ~~~~~~~~ ^
/Users/danilo/Monkey/monkey2/tmp/untitled10.buildv1.1.15/macos_release_mx/include/untitled10_untitled10.h:21:18: note: overridden virtual function is here
  virtual bbBool m_MyMethod()=0;
          ~~~~~~ ^
1 error generated.


***** Fatal mx2cc error *****

Internal mx2cc build error

It always happens when the return type does not match the interface exactly:

Interface MyInterface
    Method MyMethod:Int()
End

Class Test Implements MyInterface
    Method MyMethod:UInt()
        Return True
    End
End

Function Main()
    New Test
End

I replaced both types with 'MyMethod:Variant()' compiled fine. I'm assuming C++ doesn't allow this circumstance as I get the same error on Linux as well. Not sure if this is a proper solution.

Monkey2 should recognize the wrong signature, @scurty-labs.

The Interface-Method "MyMethod:Bool()" is missing from the Class, so Monkey2 could catch that mistake and throw an error.