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

assertIs<LNChannel<X>> doesn't work as expected #405

Closed
wants to merge 1 commit into from

Conversation

robbiehanson
Copy link
Contributor

According to the docs for assertIs:

Note that due to type erasure the type check may be partial (e.g. assertIs<List<String>>(value) only checks for the class being List and not the type of its elements because it's erased).

And we had a LOT of assertIs<LNChannel<X>> checks 😬

Note that this PR isn't finished, because we still have code like this that we need to fix:

fun <T : ChannelState> someFun(): LNChannel<T> {
  // ...
  assertIs<LNChannel<T>>(state)
  return state
}

…erifies `LNChannel`, but not `X` due to type erasure.
@robbiehanson robbiehanson changed the title Bug fix: assertIs<LNChannel<X>> doesn't work as expected assertIs<LNChannel<X>> doesn't work as expected Nov 18, 2022
@pm47
Copy link
Member

pm47 commented Nov 19, 2022

Dammit, you're right. We even touched this topic during the review: #391 (comment).

I believe that most of the time, due to us using the inner state through smart cast, the test would break in case of type mismatch though.

@robbiehanson
Copy link
Contributor Author

From the previous discussion, it sounds like there may be better ways to solve this issue.

The problem with this simple approach is that this:

assertIs<Closing>(alice.state)

does NOT tell the compiler that alice is LNChannel<Closing>. And so you get several compiler errors. Which means you either have to add a redundant check:

assertIs<LNChannel<Closing>>(alice)

or refactor a bunch of tests, somehow.

I'm closing this PR, and replacing it with issue #412

@pm47 pm47 deleted the unit-test-bugs branch October 18, 2024 11:47
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 this pull request may close these issues.

2 participants