Skip to content

ccall sometimes fails to statically evaluate arguments due to binding ages #57749

Open
@topolarity

Description

@topolarity
using Zstd_jll
const prefix = "Zstd version: "
const sym = :ZSTD_versionString
get_zstd_version() = prefix * unsafe_string(ccall((sym, libzstd), Cstring, ()))

On nightly:

julia> get_zstd_version()
ERROR: TypeError: in ccall: first argument not a pointer or valid constant expression, expected Ptr, got a value of type Tuple{Symbol, String}

It works if you swap the constant definition order:

using Zstd_jll
const sym = :ZSTD_versionString
const prefix = "Zstd version: "
get_zstd_version() = prefix * unsafe_string(ccall((sym, libzstd), Cstring, ()))
julia> get_zstd_version()
"Zstd version: 1.5.7"

This happens because the usage of prefix restricted the valid world range more tightly

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions