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

[BUG] Superclass constraints on instances get lost with data-dependencies #11455

Closed
cocreature opened this issue Oct 28, 2021 · 0 comments · Fixed by #11467
Closed

[BUG] Superclass constraints on instances get lost with data-dependencies #11455

cocreature opened this issue Oct 28, 2021 · 0 comments · Fixed by #11467
Assignees

Comments

@cocreature
Copy link
Contributor

I admit I don’t really understand what is failing here so let me start with an example:
Dependency package

-- Copyright (c) 2018-2020, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.

{-# LANGUAGE UndecidableInstances #-}

module Overlap where

class C a where
  unit : a -> ()

instance C () where
  unit _ = ()

type Syn r a = (C a, DA.Internal.Record.HasField "i" r a)

class D a where
    f : a -> ()

instance Syn r a => D r where
    f _ = ()

Main package which depends on the one above via a data-dependency

module Main where

import Overlap

data T = T with
  i : ()

x : ()
x = f (T ())

This fails in the LF typechecker (the Daml typechecker is happy)

File:     daml/Main.daml
Hidden:   no
Range:    1:1-2:1
Source:   DAML-LF typechecker
Severity: DsError
Message: 
  error type checking value Main.x:
  type mismatch:
  * expected type:
  <s_1 : <m_unit : Unit -> Unit -> Unit>;
  s_2 :
  <m_getField : Unit -> Main:T -> Unit;
  m_setField : Unit -> Unit -> Main:T -> Main:T>>
  * found type:
  <m_unit : Unit -> Unit -> Unit>
  * expression:
  676e9493c4ffe6ba1ed4e4e1a58c7e8b237a44cdb6ef2c23d9ccbf4c0994627a:Overlap:$fC()

You can see that the s_1 superclass constraint got inlined while s_2 is missing.

Looking at the generated stub code we have

instance (forall r a.
          ((Overlap.C a),
           (Pkg_83623d7b8279455f5257281ab8ec1f9a2c46c61ba44e04db94d69f98c2b74fbf.DA.Internal.Record.HasField "i" r a)) =>
          Overlap.D r) where
  f _
    = (CurrentSdk.GHC.Err.error
         (CurrentSdk.Data.String.fromString "data-dependency stub"))

What seems to be happening is that the constraint synonym gets inlined and we turn the instance for the tuple into two separate instances and then we try to typecheck the first instance against the tuple for the constraint synonym.

@cocreature cocreature added the language/now Language team priority NOW label Oct 28, 2021
@akrmn akrmn added the wip-issue This issue is being worked on. Use draft PRs for work in progress PRs. label Oct 29, 2021
moisesackerman-da pushed a commit that referenced this issue Oct 29, 2021
This is because otherwise GHC expands them out as regular constraints.

Closes #11455
Similar to #9663

changelog_begin
changelog_end
akrmn added a commit that referenced this issue Oct 29, 2021
This is because otherwise GHC expands them out as regular constraints.

Closes #11455
Similar to #9663

changelog_begin
changelog_end
@akrmn akrmn removed wip-issue This issue is being worked on. Use draft PRs for work in progress PRs. language/now Language team priority NOW labels Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants