overloading priority

26 views
Skip to first unread message

Stepan Koltsov

unread,
Aug 6, 2012, 4:29:51 PM8/6/12
to clay-l...@googlegroups.com
Hi.

While trying to reproduce https://github.com/jckarter/clay/pull/310 , I've found very interesting issue:

```
import vectors.*;
import printer.*;

main() {
    var v = Vector[Int]();
    push(v, 1);
    clear(v);
    println(v == Vector[Int]());
}
```

This code prints false. For reason I don't understand, 'equals?' from records is called instead of equals? from core.operators. How to fix that?

--
Stepan Koltsov

Joe Groff

unread,
Aug 6, 2012, 4:35:59 PM8/6/12
to clay-l...@googlegroups.com
Overloads are matched in reverse load order, so if core.records is
loaded after core.operators, its overloads will have priority.

-Joe

Stepan Koltsov

unread,
Aug 6, 2012, 4:40:03 PM8/6/12
to clay-l...@googlegroups.com


So proper solution would be adding core.sequences, moving Sequence-related functions to core.sequences and importing core.sequences after core.records?

--
Stepan Koltsov

Joe Groff

unread,
Aug 6, 2012, 4:42:54 PM8/6/12
to clay-l...@googlegroups.com
On Mon, Aug 6, 2012 at 1:40 PM, Stepan Koltsov <stepan....@gmail.com> wrote:
>
> So proper solution would be adding core.sequences, moving Sequence-related
> functions to core.sequences and importing core.sequences after core.records?
>

That sounds like it should work.

-Joe

Stepan Koltsov

unread,
Aug 6, 2012, 4:46:22 PM8/6/12
to clay-l...@googlegroups.com

I'll do it.

--
Stepan Koltsov

Stepan Koltsov

unread,
Aug 6, 2012, 5:53:22 PM8/6/12
to clay-l...@googlegroups.com


OK, I give up. I don't understand how it works enough to fix the issue. Somebody else please fix it.

Test case for the issue:

```
record MySequenceForPrecedence (
    i: Int,
);
   
record MyIteratorForPrecedence();

overload iterator(seq: MySequenceForPrecedence) = MyIteratorForPrecedence();

overload nextValue(iter: MyIteratorForPrecedence) = nothing(Int);

testSequenceEqualsHigherThatRecordPrecedence(test) {
    // if 'equal?' from records has higher precedence, this test fails
    expectEqual(test, "==", MySequenceForPrecedence(1), MySequenceForPrecedence(2));
}
```

--
Stepa

Joe Groff

unread,
Aug 6, 2012, 8:39:22 PM8/6/12
to clay-l...@googlegroups.com
I've pushed a patch that makes your test case pass. Let me know if you
find any more problems.

-Joe
Reply all
Reply to author
Forward
0 new messages