@@ -119,7 +119,7 @@ class CheckErrors : CompilerStep
119119
120120 // these modifiers are never allowed on a type
121121 if (flags.and(FConst.Ctor) != 0 ) err("Cannot use 'new' modifier on type" , loc)
122- if (flags.and(Parser .Once) != 0 ) err("Cannot use 'once' modifier on type" , loc)
122+ if (flags.and(FConst .Once) != 0 ) err("Cannot use 'once' modifier on type" , loc)
123123 if (flags.and(FConst.Override) != 0 ) err("Cannot use 'override' modifier on type" , loc)
124124 if (flags.and(FConst.Private) != 0 ) err("Cannot use 'private' modifier on type" , loc)
125125 if (flags.and(FConst.Protected) != 0 ) err("Cannot use 'protected' modifier on type" , loc)
@@ -177,16 +177,9 @@ class CheckErrors : CompilerStep
177177 // in another check
178178 t.fieldDefs.each |FieldDef f|
179179 {
180- if (! f.isConst && ! f.isStatic && f.isStorage && ! isSys)
180+ if (! f.isConst && ! f.isStatic && f.isStorage && ! isSys && ! f.isOnce )
181181 err("Const type '$t.name ' cannot contain non-const field '$f.name '" , f.loc)
182182 }
183-
184- // check that no once methods
185- t.methodDefs.each |MethodDef m|
186- {
187- if (m.isOnce)
188- err("Const type '$t.name ' cannot contain once method '$m.name '" , m.loc)
189- }
190183 }
191184
192185 private Void checkBase(TypeDef t, CType base)
@@ -256,7 +249,7 @@ class CheckErrors : CompilerStep
256249 // these modifiers are never allowed on a field
257250 if (flags.and(FConst.Ctor) != 0 ) err("Cannot use 'new' modifier on field" , loc)
258251 if (flags.and(FConst.Final) != 0 ) err("Cannot use 'final' modifier on field" , loc)
259- if (flags.and(Parser .Once) != 0 ) err("Cannot use 'once' modifier on field" , loc)
252+ if (flags.and(FConst .Once) != 0 && flags.and(FConst.Synthetic) == 0 ) err("Cannot use 'once' modifier on field" , loc)
260253
261254 // check invalid protection combinations
262255 checkProtectionFlags(flags, loc)
@@ -380,7 +373,7 @@ class CheckErrors : CompilerStep
380373 if (flags.and(FConst.Abstract) != 0 ) err("Invalid combination of 'new' and 'abstract' modifiers" , loc)
381374 else if (flags.and(FConst.Override) != 0 ) err("Invalid combination of 'new' and 'override' modifiers" , loc)
382375 else if (flags.and(FConst.Virtual) != 0 ) err("Invalid combination of 'new' and 'virtual' modifiers" , loc)
383- if (flags.and(Parser .Once) != 0 ) err("Invalid combination of 'new' and 'once' modifiers" , loc)
376+ if (flags.and(FConst .Once) != 0 ) err("Invalid combination of 'new' and 'once' modifiers" , loc)
384377 if (flags.and(FConst.Native) != 0 ) err("Invalid combination of 'new' and 'native' modifiers" , loc)
385378 }
386379
@@ -390,18 +383,18 @@ class CheckErrors : CompilerStep
390383 if (flags.and(FConst.Abstract) != 0 ) err("Invalid combination of 'static' and 'abstract' modifiers" , loc)
391384 else if (flags.and(FConst.Override) != 0 ) err("Invalid combination of 'static' and 'override' modifiers" , loc)
392385 else if (flags.and(FConst.Virtual) != 0 ) err("Invalid combination of 'static' and 'virtual' modifiers" , loc)
393- if (flags.and(Parser .Once) != 0 ) err("Invalid combination of 'static' and 'once' modifiers" , loc)
386+ if (flags.and(FConst .Once) != 0 ) err("Invalid combination of 'static' and 'once' modifiers" , loc)
394387 }
395388
396389 // check invalid abstract flags
397390 if (flags.and(FConst.Abstract) != 0 )
398391 {
399392 if (flags.and(FConst.Native) != 0 ) err("Invalid combination of 'abstract' and 'native' modifiers" , loc)
400- if (flags.and(Parser .Once) != 0 ) err("Invalid combination of 'abstract' and 'once' modifiers" , loc)
393+ if (flags.and(FConst .Once) != 0 ) err("Invalid combination of 'abstract' and 'once' modifiers" , loc)
401394 }
402395
403396 // mixins cannot have once methods
404- if (flags.and(Parser .Once) != 0 )
397+ if (flags.and(FConst .Once) != 0 )
405398 {
406399 if (curType.isMixin)
407400 err("Mixins cannot have once methods" , m.loc)
@@ -444,7 +437,11 @@ class CheckErrors : CompilerStep
444437 t := p.paramType
445438 if (t.isVoid) { err("Cannot use Void as parameter type" , p.loc); return }
446439 if (t.isThis) { err("Cannot use This as parameter type" , p.loc); return }
447- if (t.toNonNullable.signature != "|sys::This->sys::Void|" ) checkValidType(p.loc, t)
440+ func := t.deref.toNonNullable as FuncType
441+ if (func != null )
442+ checkParamFuncType(p, func)
443+ else
444+ checkValidType(p.loc, t)
448445
449446 // check parameter default type
450447 if (p.def != null && ! p.paramType.isGenericParameter)
@@ -456,6 +453,19 @@ class CheckErrors : CompilerStep
456453 }
457454 }
458455
456+ private Void checkParamFuncType(ParamDef param, FuncType t)
457+ {
458+ if (! t.ret.isVoid && ! t.ret.isValid)
459+ err("Invalid return type '$t.ret ' in func type of param '$param.name '" , param.loc)
460+
461+ // This type is allowed in func params as a co-variant position
462+ t.params.each |p|
463+ {
464+ if (! p.isThis && ! p.isValid)
465+ err("Invalid param type '$p ' in func type of param '$param.name '" , param.loc)
466+ }
467+ }
468+
459469 private Void checkMethodReturn(MethodDef m)
460470 {
461471 if (m.ret.isThis)
0 commit comments