Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
7a8ea7fd
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,发现更多精彩内容 >>
提交
7a8ea7fd
编写于
6月 02, 2011
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
JET-65 Identifier in initializer block resolves to constructor parameter instead of property
+ Scopes for secondary constructors fixed
上级
82693678
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
56 addition
and
16 deletion
+56
-16
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
+20
-15
idea/testData/checker/regression/ScopeForSecondaryConstructors.jet
...Data/checker/regression/ScopeForSecondaryConstructors.jet
+18
-0
idea/testData/resolve/PrimaryConstructors.jet
idea/testData/resolve/PrimaryConstructors.jet
+18
-1
未找到文件。
idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
浏览文件 @
7a8ea7fd
...
...
@@ -37,7 +37,6 @@ public class TopDownAnalyzer {
private
final
JetSemanticServices
semanticServices
;
private
final
ClassDescriptorResolver
classDescriptorResolver
;
private
final
BindingTraceContext
trace
;
private
boolean
readyToProcessExpressions
=
false
;
private
final
BindingTraceAdapter
traceForConstructors
;
private
final
BindingTraceAdapter
traceForMembers
;
...
...
@@ -93,7 +92,6 @@ public class TopDownAnalyzer {
resolveFunctionAndPropertyHeaders
(
declarations
);
// Constructor headers are resolved as well
readyToProcessExpressions
=
true
;
resolveBehaviorDeclarationBodies
();
}
...
...
@@ -397,7 +395,7 @@ public class TopDownAnalyzer {
final
ConstructorDescriptor
primaryConstructor
=
descriptor
.
getUnsubstitutedPrimaryConstructor
();
final
JetScope
scopeForConstructor
=
primaryConstructor
==
null
?
null
:
getInnerScopeForConstructor
(
primaryConstructor
,
descriptor
.
getScopeForMemberResolution
());
:
getInnerScopeForConstructor
(
primaryConstructor
,
descriptor
.
getScopeForMemberResolution
()
,
true
);
final
JetTypeInferrer
typeInferrer
=
semanticServices
.
getTypeInferrer
(
traceForConstructors
,
JetFlowInformationProvider
.
NONE
);
// TODO : flow
for
(
JetDelegationSpecifier
delegationSpecifier
:
jetClass
.
getDelegationSpecifiers
())
{
...
...
@@ -472,7 +470,7 @@ public class TopDownAnalyzer {
if
(
jetClass
.
hasPrimaryConstructor
())
{
ConstructorDescriptor
primaryConstructor
=
classDescriptor
.
getUnsubstitutedPrimaryConstructor
();
assert
primaryConstructor
!=
null
;
final
JetScope
scopeForConstructor
=
getInnerScopeForConstructor
(
primaryConstructor
,
classDescriptor
.
getScopeForMemberResolution
());
final
JetScope
scopeForConstructor
=
getInnerScopeForConstructor
(
primaryConstructor
,
classDescriptor
.
getScopeForMemberResolution
()
,
true
);
JetTypeInferrer
typeInferrer
=
semanticServices
.
getTypeInferrer
(
traceForConstructors
,
JetFlowInformationProvider
.
NONE
);
// TODO : flow
for
(
JetClassInitializer
anonymousInitializer
:
anonymousInitializers
)
{
typeInferrer
.
getType
(
scopeForConstructor
,
anonymousInitializer
.
getBody
(),
true
);
...
...
@@ -491,17 +489,14 @@ public class TopDownAnalyzer {
JetDeclaration
declaration
=
entry
.
getKey
();
ConstructorDescriptor
descriptor
=
entry
.
getValue
();
JetScope
declaringScope
=
declaringScopes
.
get
(
declaration
);
assert
declaringScope
!=
null
;
resolveSecondaryConstructorBody
((
JetConstructor
)
declaration
,
descriptor
,
declaringScope
);
resolveSecondaryConstructorBody
((
JetConstructor
)
declaration
,
descriptor
,
((
MutableClassDescriptor
)
descriptor
.
getContainingDeclaration
()).
getScopeForMemberResolution
());
assert
descriptor
.
getUnsubstitutedReturnType
()
!=
null
;
}
}
private
void
resolveSecondaryConstructorBody
(
JetConstructor
declaration
,
final
ConstructorDescriptor
descriptor
,
final
JetScope
declaringScope
)
{
final
JetScope
functionInnerScope
=
getInnerScopeForConstructor
(
descriptor
,
declaringScope
);
final
JetScope
functionInnerScope
=
getInnerScopeForConstructor
(
descriptor
,
declaringScope
,
false
);
final
JetTypeInferrer
typeInferrerForInitializers
=
semanticServices
.
getTypeInferrer
(
traceForConstructors
,
JetFlowInformationProvider
.
NONE
);
...
...
@@ -529,7 +524,7 @@ public class TopDownAnalyzer {
public
void
visitDelegationToThisCall
(
JetDelegatorToThisCall
call
)
{
// TODO : check that there's no recursion in this() calls
// TODO : check: if a this() call is present, no other initializers are allowed
ClassDescriptor
classDescriptor
=
(
ClassDescriptor
)
descriptor
.
getContainingDeclaration
();
ClassDescriptor
classDescriptor
=
descriptor
.
getContainingDeclaration
();
typeInferrerForInitializers
.
checkClassConstructorCall
(
functionInnerScope
,
call
.
getThisReference
(),
...
...
@@ -570,12 +565,24 @@ public class TopDownAnalyzer {
}
@NotNull
private
JetScope
getInnerScopeForConstructor
(
@NotNull
ConstructorDescriptor
descriptor
,
@NotNull
JetScope
declaringScope
)
{
private
JetScope
getInnerScopeForConstructor
(
@NotNull
ConstructorDescriptor
descriptor
,
@NotNull
JetScope
declaringScope
,
boolean
primary
)
{
WritableScope
constructorScope
=
new
WritableScopeImpl
(
declaringScope
,
declaringScope
.
getContainingDeclaration
(),
trace
.
getErrorHandler
());
for
(
PropertyDescriptor
propertyDescriptor
:
((
MutableClassDescriptor
)
descriptor
.
getContainingDeclaration
()).
getProperties
())
{
constructorScope
.
addPropertyDescriptorByFieldName
(
"$"
+
propertyDescriptor
.
getName
(),
propertyDescriptor
);
}
return
FunctionDescriptorUtil
.
getFunctionInnerScope
(
constructorScope
,
descriptor
,
trace
);
constructorScope
.
setThisType
(
descriptor
.
getContainingDeclaration
().
getDefaultType
());
for
(
ValueParameterDescriptor
valueParameterDescriptor
:
descriptor
.
getUnsubstitutedValueParameters
())
{
JetParameter
parameter
=
(
JetParameter
)
trace
.
getDeclarationPsiElement
(
valueParameterDescriptor
);
if
(
parameter
.
getValOrVarNode
()
==
null
||
!
primary
)
{
constructorScope
.
addVariableDescriptor
(
valueParameterDescriptor
);
}
}
constructorScope
.
addLabeledDeclaration
(
descriptor
);
// TODO : Labels for constructors?!
return
constructorScope
;
}
private
void
resolvePropertyDeclarationBodies
()
{
...
...
@@ -599,7 +606,7 @@ public class TopDownAnalyzer {
trace
.
getErrorHandler
().
genericError
(
initializer
.
getNode
(),
"Property initializers are not allowed when no primary constructor is present"
);
}
else
{
JetScope
scope
=
getInnerScopeForConstructor
(
primaryConstructor
,
classDescriptor
.
getScopeForMemberResolution
());
JetScope
scope
=
getInnerScopeForConstructor
(
primaryConstructor
,
classDescriptor
.
getScopeForMemberResolution
()
,
true
);
resolvePropertyInitializer
(
property
,
propertyDescriptor
,
initializer
,
scope
);
}
}
...
...
@@ -727,8 +734,6 @@ public class TopDownAnalyzer {
JetFlowInformationProvider
flowInformationProvider
=
classDescriptorResolver
.
computeFlowData
(
function
.
asElement
(),
bodyExpression
);
JetTypeInferrer
typeInferrer
=
semanticServices
.
getTypeInferrer
(
trace
,
flowInformationProvider
);
assert
readyToProcessExpressions
:
"Must be ready collecting types"
;
typeInferrer
.
checkFunctionReturnType
(
declaringScope
,
function
,
functionDescriptor
);
List
<
JetElement
>
unreachableElements
=
new
ArrayList
<
JetElement
>();
...
...
idea/testData/checker/regression/ScopeForSecondaryConstructors.jet
0 → 100644
浏览文件 @
7a8ea7fd
class Foo(var bar : Int, barr : Int, val barrr : Int) {
{
bar = 1
barr = 1
barrr = 1
1 : Int
this : Foo
}
this(val bar : Int) : this(1, 1, 1) {
bar = 1
this.bar
1 : Int
val a : Int =1
this : Foo
}
}
idea/testData/resolve/PrimaryConstructors.jet
浏览文件 @
7a8ea7fd
class A(~a~val a : Int) {
this() {`$a`a}
~b~val b = `a`a
~b~val b = `
$
a`a
~f~fun f() = `$a`a
}
...
...
@@ -10,3 +10,20 @@ fun test() {
a.`b`b`:std::Int`
a.`f`f()`:std::Int`
}
namespace Jet65 {
class Foo(~bar~var bar : Int, ~barr~barr : Int, ~barrr~val barrr : Int) {
{
`$bar`bar = 1
`barr`barr = 1
`$barrr`barrr = 1
}
this(~s.bar~val bar : Int) : this(1, 1, 1) {
`s.bar`bar = 1
this.`$bar`bar
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录