Skip to content

Commit

Permalink
fix: fixes #1852
Browse files Browse the repository at this point in the history
  • Loading branch information
leodemoura committed Nov 19, 2022
1 parent 22e96c7 commit 51a2909
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Lean/Class.lean
Expand Up @@ -88,13 +88,14 @@ def hasOutParams (env : Environment) (declName : Name) : Bool :=
-/
private partial def checkOutParam (i : Nat) (outParamFVarIds : Array FVarId) (outParams : Array Nat) (type : Expr) : Except String (Array Nat) :=
match type with
| .forallE _ d b _ =>
| .forallE _ d b bi =>
if d.isOutParam then
let fvarId := { name := Name.mkNum `_fvar outParamFVarIds.size }
let fvar := mkFVar fvarId
let b := b.instantiate1 fvar
checkOutParam (i+1) (outParamFVarIds.push fvarId) (outParams.push i) b
else if d.hasAnyFVar fun fvarId => outParamFVarIds.contains fvarId then
/- See issue #1852 for a motivation for `!bi.isInstImplicit` -/
else if !bi.isInstImplicit && d.hasAnyFVar fun fvarId => outParamFVarIds.contains fvarId then
Except.error s!"invalid class, parameter #{i+1} depends on `outParam`, but it is not an `outParam`"
else
checkOutParam (i+1) outParamFVarIds outParams b
Expand Down
5 changes: 5 additions & 0 deletions tests/lean/run/1852.lean
@@ -0,0 +1,5 @@
class foo (F : Type) where
foo : F

class foobar (F : outParam Type) [foo F] where
bar : F

1 comment on commit 51a2909

@digama0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leodemoura Could you add a test that the foobar class will find instances as though [foo F] was also an outParam? (From the code it seems like the error message is suppressed but it is not marked as an outparam, so I wonder how the typeclass instance code will handle this.)

Please sign in to comment.