feat: better error message
This commit is contained in:
parent
9e5998baf0
commit
af1cecc641
3 changed files with 18 additions and 1 deletions
|
|
@ -639,7 +639,8 @@ private partial def mkCoercionToCopiedParent (levelParams : List Name) (params :
|
|||
return result
|
||||
let declVal ← mkLambdaFVars params (← mkLambdaFVars #[source] (← copyFields parentType))
|
||||
let declName := structName ++ mkToParentName (← getStructureName parentType)
|
||||
-- TODO: nice error message if `declName` already exists
|
||||
if env.contains declName then
|
||||
throwError "failed to create coercion '{declName}' to parent structure '{parentStructName}', environment already contains a declaration with the same name"
|
||||
addAndCompile <| Declaration.defnDecl {
|
||||
name := declName
|
||||
levelParams := levelParams
|
||||
|
|
|
|||
15
tests/lean/diamond5.lean
Normal file
15
tests/lean/diamond5.lean
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class A (α : Type) where
|
||||
one : α
|
||||
zero : α
|
||||
|
||||
class B (α : Type) extends A α where
|
||||
add : α → α → α
|
||||
|
||||
class C (α : Type) extends A α where
|
||||
mul : α → α → α
|
||||
|
||||
set_option structureDiamondWarning false
|
||||
|
||||
def D.toC (x : Nat) := x
|
||||
|
||||
class D (α : Type) extends B α, C α
|
||||
1
tests/lean/diamond5.lean.expected.out
Normal file
1
tests/lean/diamond5.lean.expected.out
Normal file
|
|
@ -0,0 +1 @@
|
|||
diamond5.lean:15:32-15:35: error: failed to create coercion 'D.toC' to parent structure 'C', environment already contains a declaration with the same name
|
||||
Loading…
Add table
Reference in a new issue