-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[BUG] Cannot bind to trait with missing parameters for unbound types to check trait conformance #3290
Comments
I don't think it's related to trait bound check: it won't compile even if you remove the Smaller repro. @value
struct S[T: CollectionElement]:
...
fn g() -> S:
... I'm not sure it should work though. The compiler can't infer the return type, and I think you what want was existential which we currently don't support. |
This works though which to me expresses the same thing but it's horribly verbose @staticmethod
fn getservbyname[
T0: CollectionElement,
T1: CollectionElement,
T2: CollectionElement,
T3: CollectionElement,
T4: CollectionElement,
T5: CollectionElement,
T6: CollectionElement,
T7: CollectionElement, //,
](name: String, proto: SockProtocol = SockProtocol.TCP) -> Optional[
SockAddr[sock_family, T0, T1, T2, T3, T4, T5, T6, T7]
]:
... |
I think the error is that T1 and T2 do not have a default and you do not specify them explicitly in the function declaration. If you give it a default it compiles for me. @value
struct S[sock_family: Int](CollectionElement):
fn __init__(inout self):
pass
fn __moveinit__(inout self, owned other: Self) -> None:
pass
fn __copyinit__(inout self, other: Self) -> None:
pass
@staticmethod
fn g(inout self) -> Optional[SockAddr[Self.sock_family]]:
return Optional[SockAddr[Self.sock_family]](None)
@value
struct SockAddr[
sock_family: Int,
T0: CollectionElement = Nonetype, # does not compile if one of them does not have a default
T1: CollectionElement = NoneType,
](CollectionElement):
fn __init__(inout self):
pass
fn __moveinit__(inout self, owned other: Self) -> None:
pass
fn __copyinit__(inout self, other: Self) -> None:
pass
fn main():
var s = S[1]()
pass
|
According to the error message I assume that a check is done on the acutal object passed at compile time. And if nothing is supplied it cannot be evaluated properly. Also according to the error message. I assume that actually none T0-T9 had a default type when you got the error message ;) |
Hi, thank you for the example it made me realize what the underlying problem is. My logic itself is wrong @staticmethod
fn g0[
T0: CollectionElement,
T1: CollectionElement, //,
](address: SockAddr[sock_family, T0, T1]) -> Optional[String]:
...
@staticmethod
fn g1[
T0: CollectionElement,
T1: CollectionElement, //,
](address: SockAddr[sock_family, T0, T1]) -> Optional[
SockAddr[sock_family, T0, T1]
]:
...
@staticmethod
fn g2(address: SockAddr[sock_family, *_]) -> Optional[String]:
...
@staticmethod
fn g3(
address: SockAddr[sock_family, *_]
) -> Optional[SockAddr[sock_family, *_]]:
...
@staticmethod
fn g4(address: SockAddr[sock_family, *_]) -> Optional[__type_of(address)]:
... g0, g1, g2, and g4 work fine. The problem is that g3 has no way of inferring the types that will be going out by what is coming in, since it could be pretty much any type combination imaginable.
so @soraros you were right here 👍 , it has to either be bound to an incoming value of the same type or explicitly declared as function parameters that are not infer only ( |
Bug description
main problem is this part:
error output:
Repro:
Steps to reproduce
System information
The text was updated successfully, but these errors were encountered: