Skip to content

Redeclaration of common keyword fields in ADTs as non-common keyword fields #2807

Description

@sungshik

Describe the bug

There are inconsistencies in how the typechecker and interpreter handle redeclaration of common keyword fields in ADTs as non-common keyword fields.

To Reproduce

Typechecker:

data Foo = foo(int x = 1, int x = 5);  // Error: "Double declaration of field `x`"
data Bar(int x = 1) = bar(int x = 5);  // No error
data Baz(int x = 1) = baz(str x = ""); // No error

Interpreter:

rascal>data Foo = foo(int x = 1, int x = 5);
ok
rascal>foo().x
int: 5
rascal>data Bar(int x = 1) = bar(int x = 5);
ok
rascal>bar().x
int: 1
rascal>data Baz(int x = 1) = baz(str x = "");
io.usethesource.vallang.exceptions.RedeclaredKeywordParameterException: Keyword parameter x was declared earlier as int

Expected behavior

In general, after discussing it with @DavyLandman and @rodinaarssen, I would expect the following rules:

  1. Redeclaring a non-common keyword field as a non-common keyword field is forbidden.
  2. Redeclaring a common keyword field as a non-common keyword field with the same type is allowed (to change the default).
  3. Redeclaring a common keyword field as a non-common keyword field with a different type is forbidden.

Applied to the examples above:

  • The compiler and interpreter should report errors for Foo. The interpreter doesn't do this yet.
  • The compiler and interpreter should not report errors for Bar, and the defalut should be 5. The interpreter doesn't do this yet.
  • The compiler and interpreter should report errors for Baz. The typechecker doesn't do this yet.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions