You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BEAM: a free get in a merged stdlib capability module captures Headers.get even with the receiver type known #638
On BEAM, a receiver call whose type is known is sent to the wrong dispatcher once the stdlib has a free function of the same name in a capability module.
Reproduce
Add this free function to module TCP in src/stdlib/net/socket.kex, next to receiveChunk, along with the matching line in Mock's make TCP, implement: Net.Socket.TCP block. PR Grand standard library cleanup and refactoring #634 had both, and removed them only because of this bug.
foul get(connection: TCPConnection) -> Result<Binary?, NetError> do
match Kex.Intrinsic.NetTCP.receiveChunk(connection, 65536) do
Ok(bytes) => return Ok(Just(bytes))
Error(e) => return e.kind == Closed then Ok(None) else Error(e)
end
end
foul get(connection) = refusing(@failure, Net.TCP, "TCP has no connection")
Rebuild and run with --run:
module Dsl do
let get(path: String, n: Integer) = path
end
using Dsl
using Net.HTTP, only: [Headers]
main do
IO.printLine("${Net.HTTP.Response.text(200, "hi").headers.get("Content-Type")}")
end
What happens
Internal error: runtime error: Undefined method: get for Net.HTTP.Headers
The emitted main/0 calls kex_prelude:get, which knows nothing about Headers. Without the Dsl module, the same call is emitted as 'Kex.Net.Socket.Mock':'get'. That happens to print the right answer, but only by luck. Expected in both cases: text/plain; charset=utf-8, as the walker prints, and as spec/ufcs_free_function_vs_unimported_receiver.kex checks. That spec is how CI caught this.
The receiver's static type, Net.HTTP.Headers, is known, and importedFreeFunctionDispatch is meant to settle such a call outright ("a receiver method answers for its own type"). It looks like the extra get providers from the merged Net.Socket modules route the call past that path.
Impact
Sockets can't have a get (the next byte chunk) like FileHandle.get, so the plan for get/put as the byte primitives of Readable/Writable has to leave sockets out for now. Related: #620, #476.
Activity