2003-11-11 (Tue) [長年日記]
_ monitor.rb
Gennady Bystritskyさんという人から変更の提案をもらったのでコードの見直し。
あまりにもひどいので、テストを書いてリファクタリング。 rubyのtest/以下にテストがいろいろあるようだけど、lib直下のライブラリの テストはどこに置くべきなんだろう。
まあ、とりあえずコードだけcommitしとくか。
_ attribute parameter中のtypeof(void)
mcs(monoのC#コンパイラ)で、
[SatherNameAttribute("times!")]
[IterReturnTypeAttribute(typeof(void))]
public static __itertype_times __iter_times(int self)
{
    return new __itertype_times(self);
}
のようなコードをコンパイルしようとすると、
int.cs(301) error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression
のようなエラーになるようだ。
mcsのソースの該当部(attribute.cs:137)を見ると、
if (e is Constant) {
	result = ((Constant) e).GetValue ();
	return true;
} else if (e is TypeOf) {
	result = ((TypeOf) e).TypeArg;
	return true;
} else if (e is ArrayCreation){
	result =  ((ArrayCreation) e).EncodeAsAttribute ();
	if (result != null)
		return true;
}
result = null;
Error_AttributeArgumentNotValid (loc);
return false;
となっている。
TypeOfはtypeof演算子に対応する抽象構文木のノードを表現するクラスなのでtypeof(void) も許されそうなものだが、実はtypeof(void)はTypeOfVoidという別のクラスで表現されていて、 しかもTypeOfとTypeOfVoidには継承関係がないらしい。
ECMAの"C# Language Specification"を見てもとくにtypeof(void)だけ除外するような 記述はなさそうだし(いつものように斜め読みだけど)、Visual C#では上記のようなコードは 通るようだ。 ってことはmcsのバグかな。 (cvs updateしたら直ってたりして…最近そういうことがよくあるのだ。)
[ツッコミを入れる]