Abort when ggproto definition is circular#6648
Abort when ggproto definition is circular#6648teunbrand wants to merge 3 commits intotidyverse:mainfrom
Conversation
| parent <- super() | ||
| if (!identical(parent, x)) { | ||
| # happy path | ||
| return(fetch_ggproto(parent, name)) | ||
| } | ||
| cli::cli_abort( | ||
| "{.cls {class(x)[1]}} cannot have a circular definition." | ||
| ) |
There was a problem hiding this comment.
Does this catch circular inheritance that has a larger radius, e.g. A->B->C->A?
There was a problem hiding this comment.
Good question. No it does not. I imagine this is a less common occurrance of an already obscure problem. I don't have instant inspiration on how this would be solved without laboriously tracking all parents, which may not be worth it for throwing a rare error message.
There was a problem hiding this comment.
I don't think I've ever stumbled upon this issue in any form so I can't be the judge of that. If you feel this PR solves a real issue and what I brought up is contrived, then I'm fine accepting as-is
|
Ok, if Thomas has never encountered this issue, I'm going to argue that this too obscure of an error to be worth fixing. I'll close this PR andn the related issue. |
This PR aims to fix #6583.
AFAICT, we cannot detect this during object construction.
The second best way to detect this is in
fetch_ggproto(), as it is such a widely used accessor.Reprex from issue:
Created on 2025-09-25 with reprex v2.1.1