Skip to content
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

Incorrectly Inferred Return type #30394

Closed
JaredCrean2 opened this issue Dec 14, 2018 · 0 comments
Closed

Incorrectly Inferred Return type #30394

JaredCrean2 opened this issue Dec 14, 2018 · 0 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@JaredCrean2
Copy link
Contributor

From Discourse

Example code:

abstract type AbstractFoo end

mutable struct FooBase <: AbstractFoo
  a::Int
  # no foo_inner: terminates any recursion
end


mutable struct Foo1 <: AbstractFoo
  foo_inner::FooBase

  function Foo1()
    return new(FooBase(1))
  end
end

mutable struct Foo2 <: AbstractFoo
  foo_inner::Foo1

  function Foo2()
    return new(Foo1())
  end
end


mutable struct Foo3 <: AbstractFoo
  foo_inner::Foo2

  function Foo3()
    return new(Foo2())
  end
end


mutable struct Foo4 <: AbstractFoo
  foo_inner::Foo3

  function Foo4()
    return new(Foo3())
  end
end



# T1 <: T2 implies T1 == T2 as long as all T1 and T2 are concrete
function getInnerFoo(foo::T1, ::Type{T2}) where {T2 <: AbstractFoo, T1 <: T2}
  return foo
end

function getInnerFoo(foo::T1, ::Type{T2}) where {T1 <: AbstractFoo, T2 <: AbstractFoo}
  return getInnerFoo(foo.foo_inner, T2)
end

obj = Foo4()

obj2 = getInnerFoo(obj, Foo2)
println("typeof(obj2) = ", typeof(obj2))
@code_warntype getInnerFoo(obj, Foo2)

On Julia 0.6.2, the output is:

typeof(obj2) = Foo2
Variables:
  #self# <optimized out>
  foo::Foo4
  #unused# <optimized out>

Body:
  begin 
      return foo::Foo4
  end::Foo4
Variables:
  #self# <optimized out>
  foo::Foo4
  #unused# <optimized out>

Body:
  begin 
      return (Main.getInnerFoo)((Core.getfield)(foo::Foo4, :foo_inner)::Foo3, $(Expr(:static_parameter, 2)))::Foo3
  end::Foo3

The typeof line shows obj2 is of type Foo2, but code_warntype infers it to be Foo3. Similar result on Julia 1.0.1.

@KristofferC KristofferC added the bug Indicates an unexpected problem or unintended behavior label Dec 14, 2018
@JeffBezanson JeffBezanson self-assigned this Dec 14, 2018
JeffBezanson added a commit that referenced this issue Dec 14, 2018
This fixes a corner case where a bug is caused, counter-intuitively,
by an over-estimated intersection.
We have method signatures A and B, with A<B (A is a strict subtype).
We have a dispatch tuple X, where X<:B and !(X<:A).
However, intersection returns X for intersect(X,A). Since there
appears to be a match there and A<B, ml_matches skips the match with B.
The fix just requires dispatch tuples to be a subtype of a signature
in order to match at all.
KristofferC pushed a commit that referenced this issue Dec 20, 2018
This fixes a corner case where a bug is caused, counter-intuitively,
by an over-estimated intersection.
We have method signatures A and B, with A<B (A is a strict subtype).
We have a dispatch tuple X, where X<:B and !(X<:A).
However, intersection returns X for intersect(X,A). Since there
appears to be a match there and A<B, ml_matches skips the match with B.
The fix just requires dispatch tuples to be a subtype of a signature
in order to match at all.

(cherry picked from commit b167bc2)
@KristofferC KristofferC mentioned this issue Dec 20, 2018
52 tasks
@KristofferC KristofferC mentioned this issue Dec 30, 2018
53 tasks
KristofferC pushed a commit that referenced this issue Dec 30, 2018
This fixes a corner case where a bug is caused, counter-intuitively,
by an over-estimated intersection.
We have method signatures A and B, with A<B (A is a strict subtype).
We have a dispatch tuple X, where X<:B and !(X<:A).
However, intersection returns X for intersect(X,A). Since there
appears to be a match there and A<B, ml_matches skips the match with B.
The fix just requires dispatch tuples to be a subtype of a signature
in order to match at all.

(cherry picked from commit b167bc2)
@KristofferC KristofferC mentioned this issue Feb 4, 2019
39 tasks
KristofferC pushed a commit that referenced this issue Feb 4, 2019
This fixes a corner case where a bug is caused, counter-intuitively,
by an over-estimated intersection.
We have method signatures A and B, with A<B (A is a strict subtype).
We have a dispatch tuple X, where X<:B and !(X<:A).
However, intersection returns X for intersect(X,A). Since there
appears to be a match there and A<B, ml_matches skips the match with B.
The fix just requires dispatch tuples to be a subtype of a signature
in order to match at all.

(cherry picked from commit b167bc2)
KristofferC pushed a commit that referenced this issue Feb 11, 2019
This fixes a corner case where a bug is caused, counter-intuitively,
by an over-estimated intersection.
We have method signatures A and B, with A<B (A is a strict subtype).
We have a dispatch tuple X, where X<:B and !(X<:A).
However, intersection returns X for intersect(X,A). Since there
appears to be a match there and A<B, ml_matches skips the match with B.
The fix just requires dispatch tuples to be a subtype of a signature
in order to match at all.

(cherry picked from commit b167bc2)
KristofferC pushed a commit that referenced this issue Apr 20, 2019
This fixes a corner case where a bug is caused, counter-intuitively,
by an over-estimated intersection.
We have method signatures A and B, with A<B (A is a strict subtype).
We have a dispatch tuple X, where X<:B and !(X<:A).
However, intersection returns X for intersect(X,A). Since there
appears to be a match there and A<B, ml_matches skips the match with B.
The fix just requires dispatch tuples to be a subtype of a signature
in order to match at all.

(cherry picked from commit b167bc2)
KristofferC pushed a commit that referenced this issue Feb 20, 2020
This fixes a corner case where a bug is caused, counter-intuitively,
by an over-estimated intersection.
We have method signatures A and B, with A<B (A is a strict subtype).
We have a dispatch tuple X, where X<:B and !(X<:A).
However, intersection returns X for intersect(X,A). Since there
appears to be a match there and A<B, ml_matches skips the match with B.
The fix just requires dispatch tuples to be a subtype of a signature
in order to match at all.

(cherry picked from commit b167bc2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants