jckarter / clay

The Clay programming language
http://claylabs.com/clay
Other
402 stars 34 forks source link

Final overloads #478

Closed ghost closed 11 years ago

ghost commented 11 years ago

Implemented final overloads as discussed in #464, #383, #334.

    define foo;
    overload foo(x) {}     // foo(x:T) is final
    overload foo(y:Int) {} // ambiguous match error
    define foo;
    default foo(x) = false;
    default foo(x:Int32) = true;    //OK as foo(x:T) not final
    overload foo(x:Float32) = true; //OK as foo(x:T) not final
    default foo(x:Int32) = false;  //OK as foo(x:Int32) not final

Final overloads are switched off by default to allow the library to be incrementally updated. A compiler flag '-final-overloads' has been added to turn final overloads on.

The library has been updated with 'default' overloads to allow the bindgen tool and hello world example to compile with final overloads enabled.

Some simple tests have been added using the -final-overloads flag.

Issues:

The ambiguous match error output is currently untidy and possibly too verbose.

jckarter commented 11 years ago

Looks good to me.

ghost commented 11 years ago

Ambiguous match error reporting integrated into match failure system. This code:

define foo;
overload foo(x) = true;
overload foo(y:Int32) = false;

main() {
    foo("bar");
    foo(2);
}

produces this error (with -final-overloads):

###############################
main() {
    foo("bar");
    foo(2);
-----------^
}
###############################
../test/lang/overloads/final/ambiguous/main.clay(7,4): error: call matches ambiguous overloads
    ../test/lang/overloads/final/ambiguous/main.clay(3,0)
        matched
    ../test/lang/overloads/final/ambiguous/main.clay(2,0)
        matched

compilation context: 
    foo(Int32)
  ../test/lang/overloads/final/ambiguous/main.clay(7,4):
    main()
  /home/jeremy/dev/clay/clay/build/compiler/../../lib-clay/core/system/system.clay(23,30):
    getExitCode()
  /home/jeremy/dev/clay/clay/build/compiler/../../lib-clay/core/system/system.clay(23,26):
    runMain(Int32, Pointer[Pointer[Int8]], Static[main])
  /home/jeremy/dev/clay/clay/build/compiler/../../lib-clay/core/system/system.clay(39,13):
    callMain(Static[main], Int32, Pointer[Pointer[Int8]])
    external main
stepancheg commented 11 years ago

@agemogolk I like this pull request: language change is good, and implementation is also good.

ghost commented 11 years ago

Thanks @stepancheg . I'll just wait and see if @jckarter has any further comment on error messages before merging.

jckarter commented 11 years ago

Reusing the match failure error code is a good idea. Looks good to me.

ghost commented 11 years ago

I find the wording quite ambitious. The word default screams for another overload, and the word overload doesn't imply a final. What is so special about the word overload that you stick to it? What about apply/final(ize), apply/set, apply/fix or apply/define? overload/final is more clear too.