Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

inference results in different behavior with "is" tests #567

Closed
jmesserly opened this issue May 12, 2016 · 5 comments
Closed

inference results in different behavior with "is" tests #567

jmesserly opened this issue May 12, 2016 · 5 comments

Comments

@jmesserly
Copy link
Contributor

reported by @vsmenon in this comment

On a very related note, after #236, strong mode and standard Dart print different values for:

class Foo<T> {
  bool bar(x) => x is T;
}
void main() {
  Foo<int> foo = new Foo();
  print(foo.bar("hello"));
}

We used to reject this.


comment by me:

ah, because of inference... eeeep.

class Foo<T> {
  bool bar(x) => x is T;
}
void main() {
  Foo<int> foo = new Foo();
  var foo2 = new Foo<int>();
  print(foo.bar("hello"));
  print(foo2.bar("hello"));
}

it seems really nice if foo2 could work, even if foo doesn't.

@jmesserly
Copy link
Contributor Author

CC @leafpetersen

I'm not sure what the right answer is. With an eye towards future Dart, does this seem like something we need to address?

@lrhn
Copy link

lrhn commented May 12, 2016

On Thu, May 12, 2016 at 8:06 PM, John Messerly [email protected]
wrote:

CC @leafpetersen https://github.com/leafpetersen

I'm not sure what the right answer is. With an eye towards future Dart,
does this seem like something we need to address?

We definitely need to figure out what we want. :)
With generic methods, this problem doesn't even need a class any more:

bool isit<T>(Object x) => x is T;

main() {
  print(isit<String>("ab"));
  print(isit<int>("ab"));
  print(isit("ab"));
}

/L

Lasse R.H. Nielsen - [email protected]
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K

  • Denmark - CVR nr. 28 86 69 84

@vsmenon
Copy link
Contributor

vsmenon commented May 12, 2016

Yeah, we used to reject these statically - i.e., reject is and as checks on all types where strong mode would differ (type params, non-dynamic functions, non-dynamic generics).

We could explore doing that again.

We could also allow but throw a StrongModeError at runtime if the test on a non-ground type ever returns false.

Neither are great answers, though the latter is particularly bad. :-)

@jmesserly jmesserly changed the title interference results in different behavior with "is" tests inference results in different behavior with "is" tests Jul 1, 2016
@jmesserly
Copy link
Contributor Author

@vsmenon can we close this? not sure we have any plans to address it and Dart 2 will make it obsolete

@vsmenon
Copy link
Contributor

vsmenon commented Sep 13, 2016

yeah, not a dev_compiler issue.

@vsmenon vsmenon closed this as completed Sep 13, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants