Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear behaviour of positional / keyword parameters with same name #1199

Closed
msteindorfer opened this issue Jul 13, 2018 · 3 comments
Closed

Comments

@msteindorfer
Copy link
Member

The behaviour below was observed in the interpreter. Some on the following scenarios should probably be allowed (I didn't see a spec of keyword parameters), but the currently fail:

// Unclear behavour

data A = a(str name) | aUnknown(str name = "???");
a("hello").name // hello
aUnknown().name // NoSuchKey ; should work?
aUnknown(name = "hello").name // NoSuchKey ; should work?

data B(str name = "???") = b(str name) | bUnknown();
b("hello").name // hello
b(name = "hello").name // call failed
b("hello", name = "world").name // hello
bUnknown().name // NoSuchKey

Trivial use cases below seem to work, thus I assume it's causing issues when the same name at times can occur as positional or keyword parameter:

// Expected behaviour

data C(str name = "???") = c();
c().name // ???

data D(str name = "???") = d1() | d2();
d1().name // ???
d2().name // ???

data E = e(str name = "???");
e().name // ???
@DavyLandman
Copy link
Member

I think, that the keyword parameters (which are fields that have a default value) are not allowed to overlap with other named fields.

I quite sure that the typechecker that @PaulKlint has worked on the last year would give you an error about this.

@mahills
Copy link
Member

mahills commented Jul 14, 2018

I'll need to check, we wrote that logic a couple of years ago. If it just doing a type compatibility check, a case like A could sneak through, but B should be a re-declaration of an existing field with the same name since it is declared at the type and constructor levels.

@jurgenvinju jurgenvinju added this to the stable release feb 2020 milestone Jan 28, 2020
@jurgenvinju
Copy link
Member

jurgenvinju commented Mar 10, 2020

ok; this has been resolved by the type-checker. the interpreter does a random thing where the positional fields win. I'm calling this one "solved-by-type-checker"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants