-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Cannot implement empty interface with different interface #24193
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
Comments
This workaround seems to work but I do not believe this is right
|
I remember @spytheman said errors are not for storing in maps nor arrays but for dispatched. #23360 |
Sometimes errors are expected to happen: In any case: all types implement the empty interface, as it is a contract with no requirements. IError satisfies the requirements of an empty interface, and therefore it implements it. |
We can't store results like import net.http
struct Response {
site string
bytes int
error ?string
}
fn main() {
mut resps := []Response{}
for site in [ 'google.com', 'good-nice-cheap.com' ] {
a := http.get('http://${site}') or {
resps << Response{ site:site, error:'${err}' }
continue
}
resps << Response{ site:site, bytes:a.body.len }
}
println('${resps}')
}
|
Your example works well as an example, but it is naive to suggest this approach can be used in all situations. In my situation your approach requires me to wrap all types with a struct that contains an error field and this just causes a mess: // currently
interface Value = {}
// now I would have to wrap Value with another struct
struct ValueWrapper {
actual_value Value
error string
} Now the user always gets a struct for each and everything, and needs to access it as a property of ValueWrapper every time, and check if the property error is a string that isn't The user already has to match the type of Value, adding a Though, I could create my own |
A really good thing V's interfaces define are not only methods but fields: interface Value {
error ?string
}
struct Response {
site string
bytes int
error ?string
}
fn main() {
mut resps := []Value{}
...
resps << Response{ site:site, error:'${err}' }
... |
I think you're ignoring what I am saying |
… the new struct Nil and returned as Value, as specified by the RESP protocol Squashed commit of the following: commit f335b7d Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Wed Apr 23 11:13:41 2025 +0200 Increment version commit d55849c Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Wed Apr 23 11:08:27 2025 +0200 Fix up hset and tests commit b8632ea Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Wed Apr 23 09:52:10 2025 +0200 Minor changes commit 5f2f735 Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Thu Apr 17 10:22:28 2025 +0200 Cleanup ProtoNil commit 88c469a Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Sat Apr 12 11:36:00 2025 +0200 fix read_map commit 3edf3b7 Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Sat Apr 12 11:11:28 2025 +0200 Rewrite tests commit f4e3f5c Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Sat Apr 12 10:20:31 2025 +0200 Apparently Error does not implement an empty interface vlang/v#24193 commit f673a47 Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Fri Apr 11 17:33:17 2025 +0200 cgen error caused by option type, giving up commit 89cd633 Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Fri Apr 11 17:19:41 2025 +0200 Fix option type issue commit e0946ae Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Fri Apr 11 16:56:14 2025 +0200 Close to finish commit ddc4955 Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Fri Apr 11 11:15:00 2025 +0200 Nil implements IError commit 1e49b0f Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Fri Apr 11 10:54:20 2025 +0200 Remove comment separators commit 570761a Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Fri Apr 11 10:47:10 2025 +0200 Implement Value and Nil commit a225148 Author: Einar Hjortdal <einar-hjortdal@outlook.com> Date: Fri Apr 11 10:32:11 2025 +0200 Remove submodules
Describe the bug
An empty interface is a contract that matches all types, therefore any type implements an empty interface.
Reproduction Steps
Expected Behavior
Correctly assign Error struct implementing IError to a EverythingImplementsThis
Current Behavior
Thrown error
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.10 c2e27ef
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: