D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3469 - ICE(func.c): Regression. Calling non-template function as a template, from another module
Summary: ICE(func.c): Regression. Calling non-template function as a template, from an...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other All
: P2 regression
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2009-11-02 18:35 UTC by Ellery Newcomer
Modified: 2014-04-18 09:12 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ellery Newcomer 2009-11-02 18:35:20 UTC
// tok.d

import tok2;

class B{
 A a;
 void b(){
   a.call!(MOTHER)("HI MUM");
 }
}


// tok2.d

class A{
 void call(string s){
 }
}

//__EOF__ 

okay, compile like so:

$ dmd tok tok2
    Error: identifier 'MOTHER' is not defined

$ dmd tok2 tok
    Error: identifier 'MOTHER' is not defined
    dmd: func.c:135: virtual void FuncDeclaration::semantic(Scope*): Assertion `semanticRun <= 1' failed.
    Aborted
Comment 1 Don 2009-11-03 01:05:18 UTC
Reduced test case.
--- test.d ----------------
import test2;
void b(){
   test2.call!();
}
--- test2.d ---------------
void call(){ }
---------------------------
assert func.c(133) semanticRun <= 1

This is a regression: it worked on DMD 2.026, but failed on 2.030 and later. Fails on the current D1, as well.
When doing a DotIdExpTemplate call, it doesn't check that thing it's calling is actually a template.
Comment 2 Don 2009-11-03 03:45:48 UTC
PATCH against DMD2.036. Passes the DMD test suite + phobos unittests.
Expression.c, DotTemplateInstanceExp::semantic(). Ensure it's a template BEFORE running the semantic pass.

Index: expression.c
===================================================================
--- expression.c	(revision 234)
+++ expression.c	(working copy)
@@ -6082,6 +6082,14 @@
 	goto Lerr;
     }
     s = s2;
+    
+    td = s->toAlias()->isTemplateDeclaration();
+    if (!td)
+    {
+	error("%s is not a template", id->toChars());
+	goto Lerr;
+    }
+    
     s->semantic(sc);
     s = s->toAlias();
     td = s->isTemplateDeclaration();
Comment 3 Walter Bright 2009-12-06 00:46:48 UTC
Fixed dmd 1.053 and 2.037