Skip to content

Identical mutable struct MutRange(1, 3) == MutRange(1, 3) returns false #55007

@baiango

Description

@baiango

Julia Version

versioninfo()

Output

Julia Version 1.10.4
Commit 48d4fd4843 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

Installation Details

  1. I downloaded the Windows 64-bit installer from https://julialang-s3.julialang.org/bin/winnt/x64/1.10/julia-1.10.4-win64.exe.
  2. I used the default installation directory C:\Users\%username%\AppData\Local\Programs\Julia-1.10.4.
  3. I selected the following additional tasks:
    • Create a Start Menu entry
    • Add Julia to PATH
Icons:
- 🟩 Create a Desktop shortcut
- ✅ Create a Start Menu entry
Other:
- ✅ Add Julia to PATH
  1. I clicked the Finish button.

Minimum Reproducible Example

  1. Create a file named asd.jl with the following content:
mutable struct Range
	start::UInt32
	finish::UInt32
end

function complement_range(input::Range, exclude::Range)::Vector{Range}
	not_overlapping::Bool = input.start > exclude.finish || input.finish < exclude.start
	if not_overlapping
		return [Range(input.start, input.finish)]
	end

	result::Vector{Range} = []
	if input.start < exclude.start
		append!(result, [Range(input.start, exclude.start)])
	end
	if input.finish > exclude.finish
		append!(result, [Range(exclude.finish, input.finish)])
	end
	return result
end

function test_complement_range()::Nothing
	result = complement_range(Range(1, 10), Range(3, 7))

	println("result::", typeof(result), ": ", result)
	println("[Range(1, 3), Range(7, 10)]::",
		typeof([Range(1, 3), Range(7, 10)]), ": ",
		"[Range(1, 3), Range(7, 10)]"
	)
	println(
		"complement_range(Range(1, 10), Range(3, 7)) == [Range(1, 3), Range(7, 10)]: ",
		complement_range(Range(1, 10), Range(3, 7)) == [Range(1, 3), Range(7, 10)]
	)

	@assert [Range(1, 3), Range(7, 10)] == result

	result = complement_range(Range(10, 20), Range(3, 7))
	@assert [Range(10, 20)] == result

	result = complement_range(Range(1, 3), Range(3, 7))
	@assert [Range(1, 3)] == result

	result = complement_range(Range(7, 10), Range(3, 7))
	@assert [Range(7, 10)] == result
end

test_complement_range()
  1. Run include("asd.jl") to run the script in the Julia REPL
  • or by executing cmd in the file path bar of Windows Explorer and run the file with julia asd.jl.

Expected Output

The expected output should be:

result::Vector{Range}: [Range(1, 3), Range(7, 10)]
[Range(1, 3), Range(7, 10)]::Vector{Range}: [Range(1, 3), Range(7, 10)]
complement_range(Range(1, 10), Range(3, 7)) == [Range(1, 3), Range(7, 10)]: true

Actual Output

The actual output is:

result::Vector{Range}: Range[Range(0x00000001, 0x00000003), Range(0x00000007, 0x0000000a)]
[Range(1, 3), Range(7, 10)]::Vector{Range}: [Range(1, 3), Range(7, 10)]
complement_range(Range(1, 10), Range(3, 7)) == [Range(1, 3), Range(7, 10)]: false
ERROR: LoadError: AssertionError: [Range(1, 3), Range(7, 10)] == result
Stacktrace:
 [1] test_complement_range()
   @ Main C:\PROJECT_FOLDER\asd.jl:35
 [2] top-level scope
   @ C:\PROJECT_FOLDER\asd.jl:47
in expression starting at C:\PROJECT_FOLDER\asd.jl:47

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions