Skip to content

incorrect type intersection in tuples of types #35698

@schlichtanders

Description

@schlichtanders

Dear Core Team,

I was motivated to raise a Bug report by the small discourse discussion about the same Unreachable Reached.

I can share reproducible piece of code, but please bear with me that it reproduces my current development setup and is not minified yet (I expect it to be quite hard to minify it actually). Still, at least you can trigger it now yourself:

using Pkg
pkg"registry add https://github.com/JuliaRegistries/General"
pkg"registry add https://github.com/schlichtanders/SchlichtandersJuliaRegistry.jl"
pkg"add Traits#unreachable_reached_2020_05_01"

using Traits

@traits f1(a::Vector) where {!isempty(a)} = a[1]
# the second call will trigger Unreachable Reached,
# actually you can switch both lines, and it is still the second call
@traits f2(a::Vector{A}) where {A, Base.isconcretetype(A)} = length(a)

The second @traits line will trigger the Unreachable Reached. You can also execute f2 before f1, and then, surprisingly, f1 will trigger the Unreachable Reached. This indicates that some state-keeping is not working correctly within Julia.

Good thing is that this way one can actually inspect both macros using macroexpand.

@traits itself also has a state, however each function has its own state (at least this is the intention, I am not yet 100% sure that it currently is still the case, as this hit me in the middle of some refactoring). So my best guess is that it is some julia internal state-keeping.

Here the unreachable reached error:

Unreachable reached at 0x1169e89d5

signal (4): Illegal instruction: 4
in expression starting at REPL[3]:1
Type##kw at ./util.jl:753
normalize_func at /Users/s.sahm/.julia/packages/Traits/Ft0sy/src/Syntax/Parsing.jl:203
#parse_traitsfunction#2 at /Users/s.sahm/.julia/packages/Traits/Ft0sy/src/Syntax/Parsing.jl:106
parse_traitsfunction at /Users/s.sahm/.julia/packages/Traits/Ft0sy/src/Syntax/Parsing.jl:16 [inlined]
_traits_parsed at /Users/s.sahm/.julia/packages/Traits/Ft0sy/src/Syntax/Syntax.jl:38
_traits at /Users/s.sahm/.julia/packages/Traits/Ft0sy/src/Syntax/Syntax.jl:32
@traits at /Users/s.sahm/.julia/packages/Traits/Ft0sy/src/Syntax/Syntax.jl:22
jl_invoke_julia_macro at /Users/julia/buildbot/worker/package_macos64/build/src/ast.c:1039
jl_expand_macros at /Users/julia/buildbot/worker/package_macos64/build/src/ast.c:1101
jl_expand_with_loc at /Users/julia/buildbot/worker/package_macos64/build/src/ast.c:1179
jl_toplevel_eval_flex at /Users/julia/buildbot/worker/package_macos64/build/src/toplevel.c:634
jl_toplevel_eval_flex at /Users/julia/buildbot/worker/package_macos64/build/src/toplevel.c:764
jl_toplevel_eval at /Users/julia/buildbot/worker/package_macos64/build/src/toplevel.c:823 [inlined]
jl_toplevel_eval_in at /Users/julia/buildbot/worker/package_macos64/build/src/toplevel.c:843
eval at ./boot.jl:331
eval_user_input at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
macro expansion at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:118 [inlined]
#26 at ./task.jl:358
jl_apply at /Users/julia/buildbot/worker/package_macos64/build/src/./julia.h:1700 [inlined]
start_task at /Users/julia/buildbot/worker/package_macos64/build/src/task.c:687
Allocations: 21909506 (Pool: 21906518; Big: 2988); GC: 25
julia> versioninfo()
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)

I hope this can already enable some others to help inspecting the issue further.
With best wishes

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviortypes and dispatchTypes, subtyping and method dispatch

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions