4197 – ICE(glue.c): error in forward-referenced in/out contract

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4197 - ICE(glue.c): error in forward-referenced in/out contract
Summary: ICE(glue.c): error in forward-referenced in/out contract
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 major
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
Reported: 2010年05月16日 04:20 UTC by strtr
Modified: 2015年06月09日 05:11 UTC (History)
4 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description strtr 2010年05月16日 04:20:19 UTC
module main;
const S S1 = S();
struct S 
{
 static S func( S s_ )
 in{ assert(false,random); }
 out(result){ assert(false,random); }
 body{ return s_; }
 
 const S S2 = func(S());
}
void main(){}
--
main.d(8): Error: __error <---# should be assert failure #
main.d(12): Error: cannot evaluate func((S())) at compile time
Comment 1 Justin Spahr-Summers 2010年05月16日 10:48:17 UTC
(In reply to comment #0)
> module main;
> 
> const S S1 = S();
> 
> struct S 
> {
> static S func( S s_ )
> in{ assert(false,random); }
> out(result){ assert(false,random); }
> body{ return s_; }
> 
> const S S2 = func(S());
> }
> void main(){}
> --
> main.d(8): Error: __error <---# should be assert failure #
> main.d(12): Error: cannot evaluate func((S())) at compile time
The second argument to assert() - if present - is supposed to be a string describing the condition. The error message without the second parameter or with a string there instead is correct.
Comment 2 bearophile_hugs 2010年05月16日 11:03:13 UTC
This can be a simplified version of the same problem:
enum Foo F1 = Foo();
struct Foo {
 const Foo F2 = func();
}
Foo func() {
 assert(false, random);
 return Foo();
}
void main() {}
Comment 3 strtr 2010年05月16日 14:11:22 UTC
(In reply to comment #1)
> 
> The second argument to assert() - if present - is supposed to be a string
> describing the condition. The error message without the second parameter or
> with a string there instead is correct.
I was expecting something like :
Error: cannot implicitly cast "random" of type unknown to string
Or 
Error: "random" not defined
Comment 4 Don 2011年04月28日 13:12:33 UTC
Original title was:
"__error iso assert failure in struct function in/out statement"
A reduced test case shows it is a very general ICE.
*Any* error inside an in() or out() contract in a function that is has its semantic run through CTFE, has all errors gagged. This can result in a cryptic error message (as in the original test case), or an ICE. This one is ICE(glue.c), but I've also seen ICE(toir.c). It fails on both D1 and D2.
const Bug4197 s4197 = Bug4197();
int func4197()
in { undefined; }
body { return 0; }
struct Bug4197 {
 static const int S2 = func4197();
}


AltStyle によって変換されたページ (->オリジナル) /