apoch / epoch-language

Home of the Epoch Programming Language Project
Other
72 stars 3 forks source link

cast() is broken #148

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The cast() function overload family is busted because pattern matching does not 
work on the first parameter, which is of type Identifier.

Fix up cast() and probably fix pattern matching in general along the way.

Original issue reported on code.google.com by don.ap...@gmail.com on 2 Apr 2012 at 6:02

GoogleCodeExporter commented 9 years ago
Actually, it's worse than just pattern matching being broken.

Type inference currently considers each parameter to a function in isolation; 
this means that when cast(string, somebuffer) is called, the first parameter 
("string" of type identifier) matches multiple overloads of cast(), and causes 
an inference failure.

Type inference needs to stop returning a single type and return a vector of 
possible types instead. Inference should fail if and only if the returned type 
possibilities do NOT allow a single overload to be resolved. In this case, 
since parameter 2 ("somebuffer" of type buffer) is matched to precisely one 
overload of cast(), inference should succeed.

This will still cause issues if cast() has multiple overloads with the *second* 
type matching, because pattern matching won't narrow down the first parameter 
to the correct target type. However, fixing pattern matching is a separate 
issue from the cast() breakage in question.

Original comment by don.ap...@gmail.com on 2 Apr 2012 at 6:16

GoogleCodeExporter commented 9 years ago
So in reality this can be fixed by considering multiple hits of the same type 
to count only as a single "possibility." In other words, if four overloads of 
cast() accept a parameter of type "identifier" in the first slot, there's still 
only one possible type for that parameter - identifier.

This simplifying assumption eliminates the problem and solves some other side 
issues. Unfortunately it's turned into a major rabbit hole and led to me 
finding a half dozen other bugs, so I haven't committed the fix just yet.

Original comment by don.ap...@gmail.com on 2 Apr 2012 at 10:08