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

Lambda-accepting UnsafeBufferOperations need contracts for calls-in-place #361

Closed
JakeWharton opened this issue Jul 30, 2024 · 0 comments
Closed

Comments

@JakeWharton
Copy link
Contributor

JakeWharton commented Jul 30, 2024

Kotlin 2.0 can see through inline funs now, but it does not infer calls-in-place.

One workaround for #360 would be to do

	override fun readAtMostTo(sink: Buffer, byteCount: Long): Long {
		val bytesRead: Int
		UnsafeBufferOperations.writeToTail(sink, 1) { bytes, startIndexInclusive, endIndexExclusive ->
			val read: Int = TODO()
			bytesRead = read
			read
		}
		return bytesRead.toLong()
	}

except without the contract the compiler complains bytesRead is not initialized at the return.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants