Generics that resolve to `this` fail the type checker
- 主要語言
- C++
- 星號
- 18.7k
- 分支
- 3.1k
- 平均合併
- 1 小時 47 分鐘
- 30 天內合併 PR
- 2
描述
I have this caching method that uses a closure to do the caching. The current class instance is passed as the 1st argument to the closure. I'm trying to type check this through generics and am encountering this error.
```
/vagrant/src/Titon/Common/Cacheable.hh:56:44,48: Invalid argument (Typing[4110])
/vagrant/src/Titon/Common/Cacheable.hh:49:52,52: This is a value of generic type T
/vagrant/src/Titon/Common/Cacheable.hh:56:44,48: It is incompatible with an object of type Titon\Common\Cacheable
/vagrant/src/Titon/Common/Cacheable.hh:56:44,48: Considering the constraint on the type 'this'
```
And the method in question. https://github.com/titon/framework/blob/master/src/Titon/Common/Cacheable.hh#L49
If I remove the generics, then I get this error. (It also causes all classes that implement the method to throw errors).
```
/vagrant/src/Titon/Common/Cacheable.hh:56:18,49: Too many arguments (Typing[4105])
/vagrant/src/Titon/Common/Cacheable.hh:49:39,57: Definition is here
```
If I use a variadic callback type annotation `(function(...): mixed)`, then I get this error (in all the implementing classes).
```
/vagrant/src/Titon/View/EngineView.hh:57:73,80: Invalid argument (Typing[4039])
/vagrant/src/Titon/Common/Cacheable.hh:49:39,60: Number of arguments doesn't match
/vagrant/src/Titon/View/EngineView.hh:57:73,80: Because of this definition
```
So... is there a way to do this? Or is this a bug?
貢獻指南
評估
這個 Issue 還沒有評估資料。