Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
47934b1f
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
47934b1f
编写于
5月 03, 2012
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
KT-1575 Can't define a fix-point generic type
#KT-1575 Fixed
上级
3bdc3167
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
38 addition
and
10 deletion
+38
-10
compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java
...rc/org/jetbrains/jet/lang/resolve/DescriptorResolver.java
+34
-10
compiler/testData/diagnostics/tests/generics/kt1575-Class.jet
...iler/testData/diagnostics/tests/generics/kt1575-Class.jet
+1
-0
compiler/testData/diagnostics/tests/generics/kt1575-ClassObject.jet
...estData/diagnostics/tests/generics/kt1575-ClassObject.jet
+1
-0
compiler/testData/diagnostics/tests/generics/kt1575-Function.jet
...r/testData/diagnostics/tests/generics/kt1575-Function.jet
+2
-0
未找到文件。
compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java
浏览文件 @
47934b1f
...
...
@@ -332,16 +332,33 @@ public class DescriptorResolver {
return
typeParameterDescriptor
;
}
final
class
UpperBoundCheckerTask
{
JetTypeReference
upperBound
;
JetType
upperBoundType
;
boolean
isClassObjectConstraint
;
private
UpperBoundCheckerTask
(
JetTypeReference
upperBound
,
JetType
upperBoundType
,
boolean
classObjectConstraint
)
{
this
.
upperBound
=
upperBound
;
this
.
upperBoundType
=
upperBoundType
;
isClassObjectConstraint
=
classObjectConstraint
;
}
}
public
void
resolveGenericBounds
(
@NotNull
JetTypeParameterListOwner
declaration
,
JetScope
scope
,
List
<
TypeParameterDescriptor
>
parameters
,
BindingTrace
trace
)
{
List
<
UpperBoundCheckerTask
>
deferredUpperBoundCheckerTasks
=
Lists
.
newArrayList
();
List
<
JetTypeParameter
>
typeParameters
=
declaration
.
getTypeParameters
();
Map
<
String
,
TypeParameterDescriptor
>
parameterByName
=
Maps
.
newHashMap
();
for
(
int
i
=
0
,
typeParametersSize
=
typeParameters
.
size
();
i
<
typeParametersSize
;
i
++)
{
for
(
int
i
=
0
;
i
<
typeParameters
.
size
()
;
i
++)
{
JetTypeParameter
jetTypeParameter
=
typeParameters
.
get
(
i
);
TypeParameterDescriptor
typeParameterDescriptor
=
parameters
.
get
(
i
);
parameterByName
.
put
(
typeParameterDescriptor
.
getName
(),
typeParameterDescriptor
);
JetTypeReference
extendsBound
=
jetTypeParameter
.
getExtendsBound
();
if
(
extendsBound
!=
null
)
{
typeParameterDescriptor
.
addUpperBound
(
resolveAndCheckUpperBoundType
(
extendsBound
,
scope
,
false
,
trace
));
JetType
type
=
typeResolver
.
resolveType
(
scope
,
extendsBound
,
trace
,
false
);
typeParameterDescriptor
.
addUpperBound
(
type
);
deferredUpperBoundCheckerTasks
.
add
(
new
UpperBoundCheckerTask
(
extendsBound
,
type
,
false
));
}
}
for
(
JetTypeConstraint
constraint
:
declaration
.
getTypeConstaints
())
{
...
...
@@ -355,7 +372,12 @@ public class DescriptorResolver {
}
TypeParameterDescriptor
typeParameterDescriptor
=
parameterByName
.
get
(
referencedName
);
JetTypeReference
boundTypeReference
=
constraint
.
getBoundTypeReference
();
JetType
bound
=
boundTypeReference
!=
null
?
resolveAndCheckUpperBoundType
(
boundTypeReference
,
scope
,
constraint
.
isClassObjectContraint
(),
trace
)
:
null
;
JetType
bound
=
null
;
if
(
boundTypeReference
!=
null
)
{
bound
=
typeResolver
.
resolveType
(
scope
,
boundTypeReference
,
trace
,
false
);
deferredUpperBoundCheckerTasks
.
add
(
new
UpperBoundCheckerTask
(
boundTypeReference
,
bound
,
constraint
.
isClassObjectContraint
()));
}
if
(
typeParameterDescriptor
==
null
)
{
// To tell the user that we look only for locally defined type parameters
ClassifierDescriptor
classifier
=
scope
.
getClassifier
(
referencedName
);
...
...
@@ -400,19 +422,21 @@ public class DescriptorResolver {
}
}
}
for
(
UpperBoundCheckerTask
checkerTask
:
deferredUpperBoundCheckerTasks
)
{
checkUpperBoundType
(
checkerTask
.
upperBound
,
checkerTask
.
upperBoundType
,
checkerTask
.
isClassObjectConstraint
,
trace
);
}
}
private
JetType
resolveAndCheckUpperBoundType
(
@NotNull
JetTypeReference
upperBound
,
@NotNull
JetScope
scope
,
boolean
classObjectConstraint
,
BindingTrace
trace
)
{
JetType
jetType
=
typeResolver
.
resolveType
(
scope
,
upperBound
,
trace
,
false
);
if
(!
TypeUtils
.
canHaveSubtypes
(
JetTypeChecker
.
INSTANCE
,
jetType
))
{
if
(
classObjectConstraint
)
{
trace
.
report
(
FINAL_CLASS_OBJECT_UPPER_BOUND
.
on
(
upperBound
,
jetType
));
private
static
void
checkUpperBoundType
(
JetTypeReference
upperBound
,
JetType
upperBoundType
,
boolean
isClassObjectConstraint
,
BindingTrace
trace
)
{
if
(!
TypeUtils
.
canHaveSubtypes
(
JetTypeChecker
.
INSTANCE
,
upperBoundType
))
{
if
(
isClassObjectConstraint
)
{
trace
.
report
(
FINAL_CLASS_OBJECT_UPPER_BOUND
.
on
(
upperBound
,
upperBoundType
));
}
else
{
trace
.
report
(
FINAL_UPPER_BOUND
.
on
(
upperBound
,
jet
Type
));
trace
.
report
(
FINAL_UPPER_BOUND
.
on
(
upperBound
,
upperBound
Type
));
}
}
return
jetType
;
}
@NotNull
...
...
compiler/testData/diagnostics/tests/generics/kt1575-Class.jet
0 → 100644
浏览文件 @
47934b1f
class C<T : C<T>>
\ No newline at end of file
compiler/testData/diagnostics/tests/generics/kt1575-ClassObject.jet
0 → 100644
浏览文件 @
47934b1f
class CO<T> where class object T : CO<T>
compiler/testData/diagnostics/tests/generics/kt1575-Function.jet
0 → 100644
浏览文件 @
47934b1f
class C<T>
fun <T : C<T>> foo() {}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录