Skip to content

Bug, constructor does not check return type #47209

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

Closed
gryumov opened this issue Oct 18, 2022 · 2 comments
Closed

Bug, constructor does not check return type #47209

gryumov opened this issue Oct 18, 2022 · 2 comments
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)

Comments

@gryumov
Copy link

gryumov commented Oct 18, 2022

Constructor does not check return type

julia> struct A
           x::Int64

           function A(f::Int64, h::Int64)::Int64 # <---
               return new(f)
           end
       end

julia> A(10, 10)
A(10)
julia> versioninfo()
Julia Version 1.8.2
Commit 36034abf26 (2022-09-29 15:21 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.6.0)
  CPU: 8 × Apple M1 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 8 on 6 virtual cores
Environment:
  JULIA_EDITOR = atom  -a
  JULIA_NUM_THREADS = 8
@vtjnash vtjnash added the compiler:lowering Syntax lowering (compiler front end, 2nd stage) label Oct 19, 2022
@vtjnash
Copy link
Member

vtjnash commented Oct 19, 2022

fixed on master, possible by #44664

julia> A(10, 10)
ERROR: MethodError: Cannot `convert` an object of type A to an object of type Int64

Closest candidates are:
  convert(::Type{T}, ::Ptr) where T<:Integer
   @ Base pointer.jl:23
  convert(::Type{T}, ::T) where T<:Number
   @ Base number.jl:6
  convert(::Type{T}, ::Number) where T<:Number
   @ Base number.jl:7
  ...

Stacktrace:
 [1] A(f::Int64, h::Int64)
   @ Main ./REPL[1]:5
 [2] top-level scope
   @ REPL[2]:1

@vtjnash vtjnash closed this as completed Oct 19, 2022
@jakobnissen
Copy link
Member

Would it perhaps be a good idea to add a test case for this?

jakobnissen added a commit to jakobnissen/julia that referenced this issue Oct 19, 2022
The issue is already fixed on master, but not tested for
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

No branches or pull requests

3 participants