Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upType ambiguity not reported when it may exist? #21878
Comments
This comment has been minimized.
This comment has been minimized.
alexcrichton
referenced this issue
Feb 3, 2015
Closed
Docopt causes nil value panic when called with no arguments. #89
This comment has been minimized.
This comment has been minimized.
|
(Update:: but then again, explicitly instantiating |
kmcallister
changed the title
Ambiguity not reported when it may exist?
Type ambiguity not reported when it may exist?
Feb 3, 2015
kmcallister
added
A-typesystem
I-nominated
labels
Feb 3, 2015
This comment has been minimized.
This comment has been minimized.
|
use std::default::Default;
trait Foo: Default { fn foo(); }
impl Foo for () { fn foo() { println!("()"); } }
impl Foo for i32 { fn foo() { println!("i32"); } }
struct Error;
impl Error {
fn foo(&self) -> ! { loop {} }
}
fn bar<T: Foo>() -> Result<T, Error> { loop {} }
fn baz<T: Foo>(_: &T) { <T as Foo>::foo(); }
fn main() {
let mut a = Default::default();
|&mut:| a = bar().unwrap_or_else(|e| e.foo());
baz(&a); // ()
}Smaller case: trait Foo { fn foo(&self) -> Self; }
fn foo<T: Foo>(x: T) -> T { x.foo() }
fn main() {
// foo(x) and x.foo() should be equivalent, but aren’t
// Bad:
let _ = foo(loop {}); // error: the trait `Foo` is not implemented for the type `()`
// Good:
let _ = loop {}.foo(); // error: the type of this value must be known in this context
} |
This comment has been minimized.
This comment has been minimized.
|
This is probably because of the implicit fallback for bottom variables to |
This comment has been minimized.
This comment has been minimized.
|
(from discussion with @nikomatsakis , this may have been injected by PR #17603 ) |
This comment has been minimized.
This comment has been minimized.
|
deciding what to do with this ticket is a 1.0 polish issue. (We would like to investigate consequences of removing the fallback to |
pnkfelix
added
the
P-medium
label
Feb 5, 2015
pnkfelix
added this to the 1.0 milestone
Feb 5, 2015
pnkfelix
removed
the
I-nominated
label
Feb 5, 2015
This comment has been minimized.
This comment has been minimized.
|
It so happened that I fiddled with numeric and bot type fallbacks when trying to solve type inference issue for the new range expression. That branch reports the following error for the given testcase:
I'm looking into it now. |
edwardw
added a commit
to edwardw/rust
that referenced
this issue
Feb 6, 2015
nikomatsakis
self-assigned this
Apr 2, 2015
steveklabnik
removed this from the 1.0 milestone
May 21, 2015
brson
unassigned
nikomatsakis
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Unassigning @nikomatsakis from ancient bug. |
brson
added
T-lang
I-nominated
labels
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Nominating for close. |
This comment has been minimized.
This comment has been minimized.
|
Agreed, no bug here. TL;DR inference fallback can be surprising. Also not so relevant with |
alexcrichton commentedFeb 3, 2015
This code compiles, but I find it somewhat surprising as I have no type annotations on
_so the compiler shouldn't know what type it is (I presume it selects one of()ori32perhaps).This issue is motivated by docopt/docopt.rs#89 and isn't necessarily a bug per se, but it does seem somewhat surprising so I just want to make sure it is intended.