nddrylliog/rock — pull request #423 by shamanas (2012-06-05 20:56:49+00:00)
Title: Operator calls on objects of a child class can now correctly call the operator declaration for the base class

Why this change is ok:
- When two types are unrelated, Type NOLUCK_SCORE is returned by Type getScore() anyway
- The more unrelated two types are (further away in an inheritance diagram), the lower the score Type getScore() returns
- If two types are the same, Type getScore() returns TYPE SEED_SCORE, which is the maximum score
- The direct result of the two points above is that the most correct declaration will be chosen when using Type getScore(), rather than discarding every declaration when the call's argument and the declaration's argument are not the same

Here are some tests that pass using this version of rock and fail using the version before this commit:

// Every test must be compiled as an independent program

/* Test 1 */
operator + (left: String, right: LLong) {
"Test 1 passed" println()
}

"foo" + 42 as Int

/* Test 2 */
Foo: class {}
Bar: class extends Foo {}

operator + (left: Foo, right: T) {
"Test 2 passed" println()
}

bar: Bar
bar + 42

/* Test 3 */
Foo: class {}
Bar: class extends Foo {}

operator + (left: Foo, right: T) {
"Test 3 failed" println()
}

operator + (left: Bar, right: T) {
"Test 3 passed" println()
}

bar: Bar
bar + 42

/* Test 4 */
Foo: interface {}
Bar: interface {}
Baz: class implements Foo, Bar {}

// First declaration wins; Same as function behaviour
operator + (left: Foo, right: T) {
"Test 4 passed" println()
}

operator + (left: Bar, right: T) {
"Test 4 failed" println()
}

baz: Baz
baz + 42

/* Test 5 */
Foo: class {}
Bar: class extends Foo {}
Baz: class extends Bar {}

operator + (left: Foo, right: T) {
"Test 5 failed" println()
}

operator + (left: Bar, right: T) {
"Test 5 passed" println()
}

baz: Baz
baz + 42