Skip to content

C++ compiler build error when Interface implementation is wrong #488

@D-a-n-i-l-o

Description

@D-a-n-i-l-o

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions