Skip to content

Commit

Permalink
Add integrity checks to detect incorrect behavior in out tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MatkovIvan committed Feb 27, 2025
1 parent d42c82f commit fb421fb
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ internal class RootNodeOwner(
}

override fun onDetach(node: LayoutNode) {
layoutNodes.remove(node.semanticsId)
val existing = layoutNodes.remove(node.semanticsId)
checkNotNull(existing) {
"Invalid usage of Owner.onDetach: layoutNode was not previously attached"
}
measureAndLayoutDelegate.onNodeDetached(node)
snapshotObserver.clear(node)
needClearObservations = true
Expand Down Expand Up @@ -509,7 +512,13 @@ internal class RootNodeOwner(

override fun onPreLayoutNodeReused(layoutNode: LayoutNode, oldSemanticsId: Int) {
// Keep the mapping up to date when the semanticsId changes
layoutNodes.remove(oldSemanticsId)
val existing = layoutNodes.remove(oldSemanticsId)
checkNotNull(existing) {
"Invalid usage of Owner.onPreLayoutNodeReused: layoutNode is not found"
}
check(existing == layoutNode) {
"Invalid usage of Owner.onPreLayoutNodeReused: previous semanticsId refers another layoutNode"
}
layoutNodes[layoutNode.semanticsId] = layoutNode
}

Expand Down

0 comments on commit fb421fb

Please sign in to comment.