rascal icon indicating copy to clipboard operation
rascal copied to clipboard

Add error for ambiguity of constructors on the call and pattern site

Open jurgenvinju opened this issue 2 years ago • 1 comments

Describe the bug

Currently the type-checker provides information about possibly ambiguous declarations, where one constructor name is used in different declarations of abstract data-types:

module vis::X

data X = x(); // info message here
data Y = x(); // info message here

int f(x()) = 1; // should have an error at `x`
X g() = x();   // should have an error at `x`, and funnily enough resolves `X` to `X OR Y`? Could be another bug. 

However, in the pattern the reference resolves to an X OR Y, and does not ask for disambiguation.

Proposal to raise an error for every use of x that is ambiguous:

"Could not decide if x() is an X or an Y, please disambiguate the constructor using X::x() or Y::x();"

jurgenvinju avatar Jun 06 '23 12:06 jurgenvinju

This is an actual error because:

  • the interpreter will arbitrarily select one of the constructor, OR sometimes through an exception
  • the compiler will not be able to generate code for the expression case, AND will accept too many possibilities during pattern matching, AND can not optimize the pattern matcher to match against the reference of a ConstructorType

jurgenvinju avatar Jun 06 '23 12:06 jurgenvinju