如何为嵌套在泛型结构中的类实现运算符? [英] How do I implement an operator for a class nested in a generic struct?

查看:147
本文介绍了如何为嵌套在泛型结构中的类实现运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  struct Outer< p>< p> T> {
class Inner:Equatable {}
}

@infix func ==< T>(lhs:Outer< T> ;.Inner,rhs:Outer< T> ;.内部) - > Bool {
return lhs === rhs
}

错误,当我尝试运行该项目:

 当发射IR SIL函数@ _TFCC4Test5Outer5InnerCU__fMS1_FT_S1_ for'init'at ... /测试.swift:20:11 
<未知>:0:错误:无法执行命令:分段错误:11
<未知>:0:错误:swift frontend命令由于信号而失败(使用-v来查看调用)
命令/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift失败,退出代码为254

然而,当我在嵌套类的同时执行相同的操作时,它工作正常:

  class MyClass:Equatable {} 

@infix func ==(lhs:MyClass,rhs:MyClass) - > Bool {
return lhs === rhs
}

这是一个bug与编译器,或者我做错了什么?

解决方案

嵌套一个 struct


$ b $ https://i.stack.imgur.com/Yis0v.pngalt =在这里输入图片描述>


When I nest a class inside a generic struct and try to implement the equality operator, like this:

struct Outer<T> {
    class Inner : Equatable {}
}

@infix func == <T>(lhs: Outer<T>.Inner, rhs: Outer<T>.Inner) -> Bool {
    return lhs === rhs
}

I get the following error when I try to run the project:

While emitting IR SIL function @_TFCC4Test5Outer5InnerCU__fMS1_FT_S1_ for 'init' at .../Testing.swift:20:11
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)
Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254

However, it works fine when I do the same thing without nesting the class:

class MyClass : Equatable {}

@infix func == (lhs: MyClass, rhs: MyClass) -> Bool {
    return lhs === rhs
}

Is this a bug with the compiler, or am I doing something wrong?

解决方案

Nesting a class or struct in a generic type struct is now flagged as invalid by XCode6 Beta6

这篇关于如何为嵌套在泛型结构中的类实现运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆