Possible confusion about interfaces #5652
Replies: 2 comments 1 reply
-
I think the playground needs some improvement on how to handle the error cases. When I compiled locally with slangc.exe, I get an error message as following,
I don't think the document describes the different explicitly but here is how I understood. I tried to make an example but the compiler optimization step removes all my tricks to make the difference obvious.
|
Beta Was this translation helpful? Give feedback.
-
Sorry, I was assuming that dynamic dispatch is not supported, but it turns out that's not the case. Basically, I thought that using interfaces as struct fields was ill-formed, and the compiler simply didn't catch it. Actually, we discussed this on Discord, and the error above is about something else. When slang introduces an explicit dynamic keyword, there will be much less confusion. |
Beta Was this translation helpful? Give feedback.
-
While the documentation emphasizes that interfaces are more similar to Rust traits and Swift protocols, there are some caveats to keep in mind:
Playground Link
It makes sense that
IFloat
is not a type, but this behavior is very unclear. Currently, the compiler not only fails to provide an error message, but it can also hard crash in cases likePrinter
. This can be especially confusing for an experienced C# programmer who might find the usage ofPrinter
very natural. Adding to the confusion is the fact that interfaces can be used to declare variables.Beta Was this translation helpful? Give feedback.
All reactions