Export to GitHub

frege - issue #57

Invalid java code generated for instances of sub classes, logical errors in instance contexts not diagnosed


Posted on Sep 30, 2012 by Happy Lion

What steps will reproduce the problem? 1. Declare a 'Base' typeclass 2. Declare a 'Sub' typeclass that needs a Base type constraint 3. Implement a instance of both Base and Sub type class

What is the expected output? What do you see instead? The code should compile

Please use labels and text to provide additional information.

On the attached bug.fr file:

if you change the type constraint list order to '(Sub m, RandomTypeClass w)', the code compiles.

Whatever the type constraint list order, if you implement Base typeclass function(s) directly in Sub implementation, the code compiles

Regards,

Yorick

Comment #1

Posted on Sep 30, 2012 by Happy Lion

change bug.fr file

Attachments

Comment #2

Posted on Sep 30, 2012 by Grumpy Rabbit

I'll handle this one.

Comment #3

Posted on Sep 30, 2012 by Grumpy Rabbit

If we have

class Sub Base a => a instance Base C1 => t

for some t and then

instance Sub C2 => t

it should hold for C2 that it must constrain t no less than C1. Or, to put it differently, that C1 must be implied by C2. Yet, this is currently checked nowhere in the compiler. In addition, the order of individual constraints should be immaterial, but this is the lesser problem.

For example, the compiler accepts the following nonsense:

instance Base Ord a => Maybe a where base = error "base"

instance Sub Show a => Maybe a where sub = error "sub"

Luckily, the generated code is not valid either, so javac stops this from being compiled.

Status: Started

Labels:
Type-Defect Priority-Medium Usability