digitalmars.D.learn - is(this : myClass)
- Patrick (5/5) Oct 20 2017 The compiler seems to reject the following code in a class method:
- Jonathan M Davis (6/9) Oct 20 2017 "this" is not a type. is(T : U) is true if T is implicitly convertible t...
- Patrick (7/23) Oct 20 2017 Thank you.
- Steven Schveighoffer (5/8) Oct 20 2017 The compiler generally doesn't "fix" errors for you, it tells you there
- Patrick (8/17) Oct 20 2017 Not asking the compiler to fix my errors.
- Steven Schveighoffer (10/24) Oct 20 2017 class C
- user1234 (9/18) Oct 20 2017 Strangely this is not always true, in other contexts this is seen
- Steven Schveighoffer (4/13) Oct 20 2017 Definitely a bug. You should have to write typeof(this) (which is valid
The compiler seems to reject the following code in a class method: bool test = is(this : myClass); Could some please explain this? Thanks, Patrick
Oct 20 2017
On Friday, October 20, 2017 21:32:48 Patrick via Digitalmars-d-learn wrote:The compiler seems to reject the following code in a class method: bool test = is(this : myClass); Could some please explain this?"this" is not a type. is(T : U) is true if T is implicitly convertible to U. T and U must both be types. So, you need to use the types of this and myClass, even if that's just is(typeof(this) : typeof(myClass)) rather than explicitly using their types. - Jonathan M Davis
Oct 20 2017
On Friday, 20 October 2017 at 21:42:32 UTC, Jonathan M Davis wrote:On Friday, October 20, 2017 21:32:48 Patrick via Digitalmars-d-learn wrote:Thank you. Due to the very specific nature of the 'is' operator, why wouldn't the compiler know to implicitly query the class types? Why must it be explicitly written, typeof(this)? PatrickThe compiler seems to reject the following code in a class method: bool test = is(this : myClass); Could some please explain this?"this" is not a type. is(T : U) is true if T is implicitly convertible to U. T and U must both be types. So, you need to use the types of this and myClass, even if that's just is(typeof(this) : typeof(myClass)) rather than explicitly using their types. - Jonathan M Davis
Oct 20 2017
On 10/20/17 5:55 PM, Patrick wrote:Due to the very specific nature of the 'is' operator, why wouldn't the compiler know to implicitly query the class types? Why must it be explicitly written, typeof(this)?The compiler generally doesn't "fix" errors for you, it tells you there is a problem, and then you have to fix it. You have to be clear and unambiguous to the compiler. Otherwise debugging would be hell. -Steve
Oct 20 2017
On Friday, 20 October 2017 at 22:15:36 UTC, Steven Schveighoffer wrote:On 10/20/17 5:55 PM, Patrick wrote:Not asking the compiler to fix my errors. When would is(this, myClass) not mean: is(typeof(this) : typeof(myClass))? Why would "is(this, myClass)" be ambiguous? What other interpretation would "is(this, myClass)" imply? PatrickDue to the very specific nature of the 'is' operator, why wouldn't the compiler know to implicitly query the class types? Why must it be explicitly written, typeof(this)?The compiler generally doesn't "fix" errors for you, it tells you there is a problem, and then you have to fix it. You have to be clear and unambiguous to the compiler. Otherwise debugging would be hell. -Steve
Oct 20 2017
On 10/20/17 6:23 PM, Patrick wrote:On Friday, 20 October 2017 at 22:15:36 UTC, Steven Schveighoffer wrote:class C { } int c; C myC; is(myC : c); oops, forgot to capitalize. But compiler says "I know, you really meant is(typeof(myC) : typeof(c)) -> false. -SteveOn 10/20/17 5:55 PM, Patrick wrote:Not asking the compiler to fix my errors. When would is(this, myClass) not mean: is(typeof(this) : typeof(myClass))?Due to the very specific nature of the 'is' operator, why wouldn't the compiler know to implicitly query the class types? Why must it be explicitly written, typeof(this)?The compiler generally doesn't "fix" errors for you, it tells you there is a problem, and then you have to fix it. You have to be clear and unambiguous to the compiler. Otherwise debugging would be hell.
Oct 20 2017
On Friday, 20 October 2017 at 23:01:25 UTC, Steven Schveighoffer wrote:On 10/20/17 6:23 PM, Patrick wrote:If I explicitly wrote: is(typeof(myC) : typeof(c)) the outcome would still be false and it would still require debugging. So your example demonstrates nothing other then a type-o was made. Try again... In this unique case, the compiler should identify the class and primitive types are incompatible and should issue an error instead (and not return false). PatrickOn Friday, 20 October 2017 at 22:15:36 UTC, Steven Schveighoffer wrote:class C { } int c; C myC; is(myC : c); oops, forgot to capitalize. But compiler says "I know, you really meant is(typeof(myC) : typeof(c)) -> false. -SteveOn 10/20/17 5:55 PM, Patrick wrote:Not asking the compiler to fix my errors. When would is(this, myClass) not mean: is(typeof(this) : typeof(myClass))?Due to the very specific nature of the 'is' operator, why wouldn't the compiler know to implicitly query the class types? Why must it be explicitly written, typeof(this)?The compiler generally doesn't "fix" errors for you, it tells you there is a problem, and then you have to fix it. You have to be clear and unambiguous to the compiler. Otherwise debugging would be hell.
Oct 20 2017
On Friday, 20 October 2017 at 23:24:17 UTC, Patrick wrote:On Friday, 20 October 2017 at 23:01:25 UTC, Steven Schveighoffer wrote:But with the current compiler you would never write is(typeOf(myC) : typeof(c)) if in your mind "c" is actually a class "C" because if that is in your mind you would just write is(typeof(myC) : c) which would get you the error. You only need typeof(variable) to get to the type, there is no point in doing typeof(type), you just write type and C is a type. Right?On 10/20/17 6:23 PM, Patrick wrote:If I explicitly wrote: is(typeof(myC) : typeof(c)) the outcome would still be false and it would still require debugging. So your example demonstrates nothing other then a type-o was made. Try again... In this unique case, the compiler should identify the class and primitive types are incompatible and should issue an error instead (and not return false). PatrickOn Friday, 20 October 2017 at 22:15:36 UTC, Steven Schveighoffer wrote:class C { } int c; C myC; is(myC : c); oops, forgot to capitalize. But compiler says "I know, you really meant is(typeof(myC) : typeof(c)) -> false. -SteveOn 10/20/17 5:55 PM, Patrick wrote:Not asking the compiler to fix my errors. When would is(this, myClass) not mean: is(typeof(this) : typeof(myClass))?Due to the very specific nature of the 'is' operator, why wouldn't the compiler know to implicitly query the class types? Why must it be explicitly written, typeof(this)?The compiler generally doesn't "fix" errors for you, it tells you there is a problem, and then you have to fix it. You have to be clear and unambiguous to the compiler. Otherwise debugging would be hell.
Oct 21 2017
But with the current compiler you would never write is(typeOf(myC) : typeof(c)) if in your mind "c" is actually a class "C" because if that is in your mind you would just write is(typeof(myC) : c) which would get you the error. You only need typeof(variable) to get to the type, there is no point in doing typeof(type), you just write type and C is a type. Right?But what value is evaluating a class type to a primitive type? It will never be true? There has to be a reasonable chance for the evaulation to be true for the 'is' operator to provide value. The compiler should reject this 'is' statement or at minimum issue a warning of incompatible types. This is nonsense creep of unusable code (being able to write code that has no meaning and value). This is equivalent to writing code like the following. It is just more obfuscated: if(false) { ... } else { ... } Patrick
Oct 21 2017
On Friday, 20 October 2017 at 21:42:32 UTC, Jonathan M Davis wrote:On Friday, October 20, 2017 21:32:48 Patrick via Digitalmars-d-learn wrote:Strangely this is not always true, in other contexts this is seen as atype, although probably a bug class Foo { class Bar : this {} static assert(is(Bar : Foo)); }The compiler seems to reject the following code in a class method: bool test = is(this : myClass); Could some please explain this?"this" is not a type.
Oct 20 2017
On 10/20/17 7:04 PM, user1234 wrote:Strangely this is not always true, in other contexts this is seen as atype, although probably a bug class Foo { class Bar : this {} static assert(is(Bar : Foo)); }Definitely a bug. You should have to write typeof(this) (which is valid in this context). -Steve
Oct 20 2017