Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2eb47629
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2eb47629
编写于
7月 19, 2011
作者:
L
Lindsey Kuper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Typechecking self-calls in anon objs. Closes #540.
上级
64fb39cd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
34 deletion
+51
-34
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+50
-30
src/test/run-pass/anon-obj-with-self-call-2.rs
src/test/run-pass/anon-obj-with-self-call-2.rs
+0
-2
src/test/run-pass/anon-obj-with-self-call.rs
src/test/run-pass/anon-obj-with-self-call.rs
+1
-2
未找到文件。
src/comp/middle/typeck.rs
浏览文件 @
2eb47629
...
...
@@ -55,8 +55,9 @@
tag
obj_info
{
// Regular objects have a node_id at compile time.
regular_obj
(
ast
::
obj_field
[],
ast
::
node_id
);
// Anonymous objects only have a type at compile time.
anon_obj
(
ast
::
obj_field
[],
ty
::
t
);
// Anonymous objects only have a type at compile time. It's optional
// because not all anonymous objects have a with_obj to attach to.
anon_obj
(
ast
::
obj_field
[],
option
::
t
[
ty
::
sty
]);
}
type
crate_ctxt
=
rec
(
mutable
obj_info
[]
obj_infos
,
ty
::
ctxt
tcx
);
...
...
@@ -2114,7 +2115,8 @@ fn check_binop_type_compat(&@fn_ctxt fcx, span span,
}
case
(
ast
::
expr_self_method
(
?
ident
))
{
auto
t
=
ty
::
mk_nil
(
fcx
.ccx.tcx
);
let
ty
::
t
this_obj_ty
=
ty
::
mk_nil
(
fcx
.ccx.tcx
);
let
option
::
t
[
ty
::
sty
]
this_obj_sty
=
some
(
structure_of
(
fcx
,
expr
.span
,
ty
::
mk_nil
(
fcx
.ccx.tcx
)));
let
option
::
t
[
obj_info
]
this_obj_info
=
get_obj_info
(
fcx
.ccx
);
alt
(
this_obj_info
)
{
case
(
some
(
?
oinfo
))
{
...
...
@@ -2128,7 +2130,10 @@ fn check_binop_type_compat(&@fn_ctxt fcx, span span,
// If we're typechecking a self-method on
// a regular object, this lookup should
// succeed.
this_obj_ty
=
tpt
._1
;
this_obj_sty
=
some
(
structure_of
(
fcx
,
expr
.span
,
tpt
._1
));
}
case
(
none
)
{
fcx
.ccx.tcx.sess
.bug
(
...
...
@@ -2137,8 +2142,8 @@ fn check_binop_type_compat(&@fn_ctxt fcx, span span,
}
}
}
case
(
anon_obj
(
_
,
?
obj_ty
))
{
this_obj_
ty
=
obj_
ty
;
case
(
anon_obj
(
_
,
?
obj_
s
ty
))
{
this_obj_
sty
=
obj_s
ty
;
}
}
}
...
...
@@ -2151,15 +2156,21 @@ fn check_binop_type_compat(&@fn_ctxt fcx, span span,
}
// Grab this method's type out of the current object type.
alt
(
structure_of
(
fcx
,
expr
.span
,
this_obj_ty
))
{
case
(
ty
::
ty_obj
(
?
methods
))
{
for
(
ty
::
method
method
in
methods
)
{
if
(
method
.ident
==
ident
)
{
t
=
ty
::
method_ty_to_fn_ty
(
fcx
.ccx.tcx
,
method
);
alt
(
this_obj_sty
)
{
case
(
some
(
?
sty
))
{
alt
(
sty
)
{
case
(
ty
::
ty_obj
(
?
methods
))
{
for
(
ty
::
method
method
in
methods
)
{
if
(
method
.ident
==
ident
)
{
t
=
ty
::
method_ty_to_fn_ty
(
fcx
.ccx.tcx
,
method
);
}
}
}
case
(
_
)
{
fail
;
}
}
}
case
(
_
)
{
fail
;
}
case
(
none
)
{
}
}
write
::
ty_only_fixup
(
fcx
,
id
,
t
);
require_impure
(
fcx
.ccx.tcx.sess
,
fcx
.purity
,
expr
.span
);
...
...
@@ -2442,40 +2453,49 @@ fn get_anon_obj_method_types(@fn_ctxt fcx,
// Typecheck 'with_obj'. If it exists, it had better have
// object type.
let
ty
::
method
[]
with_obj_methods
=
~
[];
auto
with_obj_ty
=
ty
::
mk_nil
(
fcx
.ccx.tcx
);
let
ty
::
t
with_obj_ty
=
ty
::
mk_nil
(
fcx
.ccx.tcx
);
let
option
::
t
[
ty
::
sty
]
with_obj_sty
=
none
;
alt
(
ao
.with_obj
)
{
case
(
none
)
{
}
case
(
some
(
?
e
))
{
// If there's a with_obj, we push it onto the
// obj_infos stack so that self-calls can be checked
// within its context later.
check_expr
(
fcx
,
e
);
with_obj_ty
=
expr_ty
(
fcx
.ccx.tcx
,
e
);
alt
(
structure_of
(
fcx
,
e
.span
,
with_obj_ty
))
{
case
(
ty
::
ty_obj
(
?
ms
))
{
with_obj_methods
=
ms
;
}
case
(
_
)
{
// The user is trying to extend a non-object.
fcx
.ccx.tcx.sess
.span_fatal
(
e
.span
,
syntax
::
print
::
pprust
::
expr_to_str
(
e
)
+
" does not have object type"
);
with_obj_sty
=
some
(
structure_of
(
fcx
,
e
.span
,
with_obj_ty
));
alt
(
with_obj_sty
)
{
case
(
none
)
{
}
case
(
some
(
?
sty
))
{
alt
(
sty
)
{
case
(
ty
::
ty_obj
(
?
ms
))
{
with_obj_methods
=
ms
;
}
case
(
_
)
{
// The user is trying to extend a
// non-object.
fcx
.ccx.tcx.sess
.span_fatal
(
e
.span
,
syntax
::
print
::
pprust
::
expr_to_str
(
e
)
+
" does not have object type"
);
}
}
}
}
}
}
log_err
"Pushing an anon obj onto the obj_infos stack..."
;
fn
anon_obj_field_to_obj_field
(
&
ast
::
anon_obj_field
f
)
fn
ao_field_to_o_field
(
&
ast
::
anon_obj_field
f
)
->
ast
::
obj_field
{
ret
rec
(
mut
=
f
.mut
,
ty
=
f
.ty
,
ident
=
f
.ident
,
id
=
f
.id
);
}
fcx
.ccx.obj_infos
+=
~
[
anon_obj
(
ivec
::
map
(
anon_obj_field_to_obj_field
,
fields
),
with_obj_ty
)];
~
[
anon_obj
(
ivec
::
map
(
ao_field_to_o_field
,
fields
),
with_obj_sty
)];
methods
+=
with_obj_methods
;
ret
methods
;
}
...
...
src/test/run-pass/anon-obj-with-self-call-2.rs
浏览文件 @
2eb47629
//xfail-stage0
//xfail-stage1
//xfail-stage2
// Reduced test case for issue #540.
fn
main
()
{
...
...
src/test/run-pass/anon-obj-with-self-call.rs
浏览文件 @
2eb47629
//xfail-stage0
//xfail-stage1
//xfail-stage2
use
std
;
fn
main
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录