OLD | NEW |
(Empty) | |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 <!DOCTYPE html> |
| 8 <html lang="en"> |
| 9 <head> |
| 10 <meta charset="utf-8"> |
| 11 |
| 12 |
| 13 |
| 14 <link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/frame
works-d7b19415c108234b91acac0d0c02091c860993c13687a757ee345cc1ecd3a9d1.css" medi
a="all" rel="stylesheet" /> |
| 15 <link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/githu
b-678c6c9fa597e3eabad2135736d58fe40e2ef37d8e272589d7d39d7c1c0f9056.css" media="a
ll" rel="stylesheet" /> |
| 16 |
| 17 |
| 18 <link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/site-
537c466d44a69d38c4bd60c2fd2955373ef96d051bd97b2ad30ed039acc97bff.css" media="all
" rel="stylesheet" /> |
| 19 |
| 20 |
| 21 <meta name="viewport" content="width=device-width"> |
| 22 |
| 23 <title>INFORMAL SPECIFICATION: Generic Method Syntax · GitHub</title> |
| 24 <link rel="search" type="application/opensearchdescription+xml" href="/opensea
rch.xml" title="GitHub"> |
| 25 <link rel="fluid-icon" href="https://gist.github.com/fluidicon.png" title="Git
Hub"> |
| 26 <meta property="fb:app_id" content="1401488693436528"> |
| 27 |
| 28 |
| 29 <meta content="https://avatars3.githubusercontent.com/u/9606994?v=3&s=40
0" property="og:image" /><meta content="Gist" property="og:site_name" /><meta co
ntent="object" property="og:type" /><meta content="INFORMAL SPECIFICATION: Gener
ic Method Syntax" property="og:title" /><meta content="https://gist.github.com/e
ernstg/4353d7b4f669745bed3a5423e04a453c" property="og:url" /><meta content="INFO
RMAL SPECIFICATION: Generic Method Syntax" property="og:description" /> |
| 30 |
| 31 <link rel="assets" href="https://assets-cdn.github.com/"> |
| 32 |
| 33 <meta name="pjax-timeout" content="1000"> |
| 34 |
| 35 <meta name="request-id" content="C852:2758B:2C020EC:46C8F04:58FDDC55" data-pja
x-transient> |
| 36 |
| 37 |
| 38 <meta name="selected-link" value="gist_code" data-pjax-transient> |
| 39 |
| 40 <meta name="google-site-verification" content="KT5gs8h0wvaagLKAVWq8bbeNwnZZK1r
1XQysX3xurLU"> |
| 41 <meta name="google-site-verification" content="ZzhVyEFwb7w3e0-uOTltm8Jsck2F5StVi
hD0exw2fsA"> |
| 42 <meta name="google-analytics" content="UA-3769691-4"> |
| 43 |
| 44 <meta content="collector.githubapp.com" name="octolytics-host" /><meta content="
gist" name="octolytics-app-id" /><meta content="https://collector.githubapp.com/
github-external/browser_event" name="octolytics-event-url" /><meta content="C852
:2758B:2C020EC:46C8F04:58FDDC55" name="octolytics-dimension-request_id" /> |
| 45 <meta content="/<user-name>/<gist-id>" data-pjax-transient="true" na
me="analytics-location" /> |
| 46 |
| 47 |
| 48 |
| 49 |
| 50 <meta class="js-ga-set" name="dimension1" content="Logged Out"> |
| 51 |
| 52 |
| 53 |
| 54 <meta content="true" name="octolytics-dimension-public" /><meta content="411
32114" name="octolytics-dimension-gist_id" /><meta content="4353d7b4f669745bed3a
5423e04a453c" name="octolytics-dimension-gist_name" /><meta content="false" name
="octolytics-dimension-anonymous" /><meta content="9606994" name="octolytics-dim
ension-owner_id" /><meta content="eernstg" name="octolytics-dimension-owner_logi
n" /><meta content="false" name="octolytics-dimension-forked" /> |
| 55 |
| 56 <meta class="js-ga-set" name="dimension5" content="public"> |
| 57 <meta class="js-ga-set" name="dimension6" content="owned"> |
| 58 <meta class="js-ga-set" name="dimension7" content="markdown"> |
| 59 |
| 60 |
| 61 <meta name="hostname" content="gist.github.com"> |
| 62 <meta name="user-login" content=""> |
| 63 |
| 64 <meta name="expected-hostname" content="gist.github.com"> |
| 65 <meta name="js-proxy-site-detection-payload" content="NmU3OWQ3MzkzZjM0NTExNT
EwNTllMzQ0ZTFmMTlkYmUxNjJhYzgzNzg3YmRhMGFhY2RiYjVmZDY2ZTAzY2JhOHx7InJlbW90ZV9hZG
RyZXNzIjoiMTA0LjEzMi4xODAuMTk4IiwicmVxdWVzdF9pZCI6IkM4NTI6Mjc1OEI6MkMwMjBFQzo0Nk
M4RjA0OjU4RkREQzU1IiwidGltZXN0YW1wIjoxNDkzMDMyMDIyLCJob3N0IjoiZ2l0aHViLmNvbSJ9"> |
| 66 |
| 67 |
| 68 <meta name="html-safe-nonce" content="6bd8afb890a51ca8210a32e1cf447ea96e2bdc74
"> |
| 69 |
| 70 <meta http-equiv="x-pjax-version" content="2e017d75c6ea5cb7f0c7e24d0a0382b8"> |
| 71 |
| 72 |
| 73 <link href="/eernstg.atom" rel="alternate" title="atom" type="application/
atom+xml"> |
| 74 |
| 75 <link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/gist-
67dd5139d22e4e9921ef362b5458f51e5973a20db04a54c9d74116748f852917.css" media="all
" rel="stylesheet" /> |
| 76 |
| 77 |
| 78 |
| 79 |
| 80 <meta name="browser-stats-url" content="https://api.github.com/_private/browse
r/stats"> |
| 81 |
| 82 <meta name="browser-errors-url" content="https://api.github.com/_private/brows
er/errors"> |
| 83 |
| 84 <link rel="mask-icon" href="https://assets-cdn.github.com/pinned-octocat.svg"
color="#000000"> |
| 85 <link rel="icon" type="image/x-icon" href="https://assets-cdn.github.com/favic
on.ico"> |
| 86 |
| 87 <meta name="theme-color" content="#1e2327"> |
| 88 |
| 89 |
| 90 |
| 91 </head> |
| 92 |
| 93 <body class="logged-out env-production"> |
| 94 |
| 95 |
| 96 |
| 97 <div class="position-relative js-header-wrapper "> |
| 98 <a href="#start-of-content" tabindex="1" class="accessibility-aid js-skip-to
-content">Skip to content</a> |
| 99 <div id="js-pjax-loader-bar" class="pjax-loader-bar"><div class="progress"><
/div></div> |
| 100 |
| 101 |
| 102 |
| 103 |
| 104 |
| 105 |
| 106 |
| 107 <div class="header gist-header header-logged-out" role="banner"> |
| 108 <div class="container clearfix"> |
| 109 |
| 110 <a href="/" aria-label="Gist Homepage" class="header-logo-wordmark" data-hot
key="g d"> |
| 111 <svg aria-hidden="true" class="octicon octicon-logo-github" height="28" ve
rsion="1.1" viewBox="0 0 45 16" width="78"><path fill-rule="evenodd" d="M18.53 1
2.03h-.02c.009 0 .015.01.024.011h.006l-.01-.01zm.004.011c-.093.001-.327.05-.574.
05-.78 0-1.05-.36-1.05-.83V8.13h1.59c.09 0 .16-.08.16-.19v-1.7c0-.09-.08-.17-.16
-.17h-1.59V3.96c0-.08-.05-.13-.14-.13h-2.16c-.09 0-.14.05-.14.13v2.17s-1.09.27-1
.16.28c-.08.02-.13.09-.13.17v1.36c0 .11.08.19.17.19h1.11v3.28c0 2.44 1.7 2.69 2.
86 2.69.53 0 1.17-.17 1.27-.22.06-.02.09-.09.09-.16v-1.5a.177.177 0 0 0-.146-.18
zm23.696-2.2c0-1.81-.73-2.05-1.5-1.97-.6.04-1.08.34-1.08.34v3.52s.49.34 1.22.36c
1.03.03 1.36-.34 1.36-2.25zm2.43-.16c0 3.43-1.11 4.41-3.05 4.41-1.64 0-2.52-.83-
2.52-.83s-.04.46-.09.52c-.03.06-.08.08-.14.08h-1.48c-.1 0-.19-.08-.19-.17l.02-11
.11c0-.09.08-.17.17-.17h2.13c.09 0 .17.08.17.17v3.77s.82-.53 2.02-.53l-.01-.02c1
.2 0 2.97.45 2.97 3.88zm-8.72-3.61H33.84c-.11 0-.17.08-.17.19v5.44s-.55.39-1.3.3
9-.97-.34-.97-1.09V6.25c0-.09-.08-.17-.17-.17h-2.14c-.09 0-.17.08-.17.17v5.11c0
2.2 1.23 2.75 2.92 2.75 1.39 0 2.52-.77 2.52-.77s.05.39.08.45c.02.05.09.09.16.09
h1.34c.11 0 .17-.08.17-.17l.02-7.47c0-.09-.08-.17-.19-.17zm-23.7-.01h-2.13c-.09
0-.17.09-.17.2v7.34c0 .2.13.27.3.27h1.92c.2 0 .25-.09.25-.27V6.23c0-.09-.08-.17-
.17-.17zm-1.05-3.38c-.77 0-1.38.61-1.38 1.38 0 .77.61 1.38 1.38 1.38.75 0 1.36-.
61 1.36-1.38 0-.77-.61-1.38-1.36-1.38zm16.49-.25h-2.11c-.09 0-.17.08-.17.17v4.09
h-3.31V2.6c0-.09-.08-.17-.17-.17h-2.13c-.09 0-.17.08-.17.17v11.11c0 .09.09.17.17
.17h2.13c.09 0 .17-.08.17-.17V8.96h3.31l-.02 4.75c0 .09.08.17.17.17h2.13c.09 0 .
17-.08.17-.17V2.6c0-.09-.08-.17-.17-.17zM8.81 7.35v5.74c0 .04-.01.11-.06.13 0 0-
1.25.89-3.31.89-2.49 0-5.44-.78-5.44-5.92S2.58 1.99 5.1 2c2.18 0 3.06.49 3.2.58.
04.05.06.09.06.14L7.94 4.5c0 .09-.09.2-.2.17-.36-.11-.9-.33-2.17-.33-1.47 0-3.05
.42-3.05 3.73s1.5 3.7 2.58 3.7c.92 0 1.25-.11 1.25-.11v-2.3H4.88c-.11 0-.19-.08-
.19-.17V7.35c0-.09.08-.17.19-.17h3.74c.11 0 .19.08.19.17z"/></svg> |
| 112 <svg aria-hidden="true" class="octicon octicon-logo-gist" height="28" vers
ion="1.1" viewBox="0 0 25 16" width="40"><path fill-rule="evenodd" d="M4.7 8.73h
2.45v4.02c-.55.27-1.64.34-2.53.34-2.56 0-3.47-2.2-3.47-5.05 0-2.85.91-5.06 3.48-
5.06 1.28 0 2.06.23 3.28.73V2.66C7.27 2.33 6.25 2 4.63 2 1.13 2 0 4.69 0 8.03c0
3.34 1.11 6.03 4.63 6.03 1.64 0 2.81-.27 3.59-.64V7.73H4.7v1zm6.39 3.72V6.06h-1.
05v6.28c0 1.25.58 1.72 1.72 1.72v-.89c-.48 0-.67-.16-.67-.7v-.02zm.25-8.72c0-.44
-.33-.78-.78-.78s-.77.34-.77.78.33.78.77.78.78-.34.78-.78zm4.34 5.69c-1.5-.13-1.
78-.48-1.78-1.17 0-.77.33-1.34 1.88-1.34 1.05 0 1.66.16 2.27.36v-.94c-.69-.3-1.5
2-.39-2.25-.39-2.2 0-2.92 1.2-2.92 2.31 0 1.08.47 1.88 2.73 2.08 1.55.13 1.77.63
1.77 1.34 0 .73-.44 1.42-2.06 1.42-1.11 0-1.86-.19-2.33-.36v.94c.5.2 1.58.39 2.
33.39 2.38 0 3.14-1.2 3.14-2.41 0-1.28-.53-2.03-2.75-2.23h-.03zm8.58-2.47v-.86h-
2.42v-2.5l-1.08.31v2.11l-1.56.44v.48h1.56v5c0 1.53 1.19 2.13 2.5 2.13.19 0 .52-.
02.69-.05v-.89c-.19.03-.41.03-.61.03-.97 0-1.5-.39-1.5-1.34V6.94h2.42v.02-.01z"/
></svg> |
| 113 </a> |
| 114 <div class="site-search js-site-search" role="search"> |
| 115 <div class="header-search" role="search"> |
| 116 |
| 117 <!-- '"` --><!-- </textarea></xmp> --></option></form><form accept-charset="UTF-
8" action="/search" class="position-relative" method="get"><div style="margin:0;
padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></
div> |
| 118 <label class="header-search-wrapper form-control js-chromeless-input-container
"> |
| 119 <input type="text" |
| 120 class="form-control js-site-search-focus header-search-input" |
| 121 data-hotkey="s" |
| 122 name="q" |
| 123 placeholder="Search…" |
| 124 tabindex="1" |
| 125 autocorrect="off" |
| 126 autocomplete="off" |
| 127 autocapitalize="off"> |
| 128 </label> |
| 129 |
| 130 </form></div> |
| 131 |
| 132 </div> |
| 133 <ul class="header-nav float-left" role="navigation"> |
| 134 <li class="header-nav-item"> |
| 135 <a href="/discover" class="header-nav-link" data-ga-click="Header, go to
all gists, text:all gists">All gists</a> |
| 136 </li> |
| 137 |
| 138 <li class="header-nav-item"> |
| 139 <a href="https://github.com" class="header-nav-link" data-ga-click="Head
er, go to GitHub, text:GitHub">GitHub</a> |
| 140 </li> |
| 141 </ul> |
| 142 |
| 143 <div class="header-actions" role="navigation"> |
| 144 <a href="/join?source=header-gist" class="btn btn-primary" data-ga-cli
ck="Header, sign up">Sign up for a GitHub account</a> |
| 145 <a href="https://gist.github.com/auth/github?return_to=gist" class="btn"
data-ga-click="Header, sign in">Sign in</a> |
| 146 </div> |
| 147 </div> |
| 148 </div> |
| 149 |
| 150 |
| 151 |
| 152 </div> |
| 153 |
| 154 <div id="start-of-content" class="accessibility-aid"></div> |
| 155 |
| 156 <div id="js-flash-container"> |
| 157 </div> |
| 158 |
| 159 |
| 160 |
| 161 <div role="main"> |
| 162 <div itemscope itemtype="http://schema.org/Code"> |
| 163 <div id="gist-pjax-container" class="gist-content-wrapper" data-pjax-contain
er> |
| 164 |
| 165 |
| 166 |
| 167 <div class="gist-detail-intro gist-banner"> |
| 168 <div class="container"> |
| 169 <a href="/" class="btn btn-outline float-right">Create a gist now</a> |
| 170 <p class="lead"> |
| 171 Instantly share code, notes, and snippets. |
| 172 </p> |
| 173 </div> |
| 174 </div> |
| 175 |
| 176 |
| 177 <div class="gisthead pagehead repohead instapaper_ignore readability-menu experi
ment-repo-nav mb-4"> |
| 178 <div class="container"> |
| 179 |
| 180 |
| 181 <div class="container repohead-details-container"> |
| 182 |
| 183 <ul class="pagehead-actions"> |
| 184 |
| 185 |
| 186 <li> |
| 187 <a href="/login?return_to=https%3A%2F%2Fgist.github.com%2Feernstg%2F4353
d7b4f669745bed3a5423e04a453c" aria-label="You must be signed in to star a gist"
class="btn btn-sm btn-with-count tooltipped tooltipped-n" rel="nofollow"> |
| 188 <svg aria-hidden="true" class="octicon octicon-star" height="16" version="1.
1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M14 6l-4.9-.64L7
1 4.9 5.36 0 6l3.6 3.26L2.67 14 7 11.67 11.33 14l-.93-4.74z"/></svg> |
| 189 Star |
| 190 </a> |
| 191 <a href="/eernstg/4353d7b4f669745bed3a5423e04a453c/stargazers" aria-label="0 u
sers starred this gist" class="social-count"> |
| 192 0 |
| 193 </a> |
| 194 </li> |
| 195 |
| 196 <li> |
| 197 <a href="/login?return_to=https%3A%2F%2Fgist.github.com%2Feernstg%2F43
53d7b4f669745bed3a5423e04a453c" aria-label="You must be signed in to fork a gist
" class="btn btn-sm btn-with-count tooltipped tooltipped-n" rel="nofollow"> |
| 198 <svg aria-hidden="true" class="octicon octicon-repo-forked" height="16" vers
ion="1.1" viewBox="0 0 10 16" width="10"><path fill-rule="evenodd" d="M8 1a1.993
1.993 0 0 0-1 3.72V6L5 8 3 6V4.72A1.993 1.993 0 0 0 2 1a1.993 1.993 0 0 0-1 3.7
2V6.5l3 3v1.78A1.993 1.993 0 0 0 5 15a1.993 1.993 0 0 0 1-3.72V9.5l3-3V4.72A1.99
3 1.993 0 0 0 8 1zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.
2 1.2 0 .65-.55 1.2-1.2 1.2zm3 10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65
0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3-10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.
2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"/></svg> |
| 199 Fork |
| 200 </a> |
| 201 <a href="/eernstg/4353d7b4f669745bed3a5423e04a453c/forks" aria-label="0 users
forked this gist" class="social-count"> |
| 202 0 |
| 203 </a> |
| 204 </li> |
| 205 |
| 206 </ul> |
| 207 |
| 208 <h1 class="public css-truncate"> |
| 209 <img alt="@eernstg" class="avatar gist-avatar" height="26" src="https://avat
ars1.githubusercontent.com/u/9606994?v=3&s=52" width="26" /> |
| 210 <span class="author"><a href="/eernstg" class="url fn" rel="author"><span it
emprop="author">eernstg</span></a></span><!-- |
| 211 --><span class="path-divider">/</span><!-- |
| 212 --><strong itemprop="name" class="gist-header-title css-truncate-target"
><a href="/eernstg/4353d7b4f669745bed3a5423e04a453c">GenericMethodSyntax.md</a><
/strong> |
| 213 |
| 214 <div class="gist-timestamp">Last active <time-ago datetime="2017-01-26T16:00
:50Z">Jan 26, 2017</time-ago></div> |
| 215 </h1> |
| 216 </div> |
| 217 |
| 218 <div class="container gist-file-navigation"> |
| 219 <div class="float-right file-navigation-options" data-multiple> |
| 220 |
| 221 <div class="file-navigation-option"> |
| 222 <input type="hidden" name="protocol_type" value="clone"> |
| 223 |
| 224 <div class="select-menu js-menu-container js-select-menu"> |
| 225 <div class="input-group js-select-button js-zeroclipboard-container"> |
| 226 <div class="input-group-button"> |
| 227 <button type="button" class="btn btn-sm select-menu-button js-menu-target" dat
a-ga-click="Repository, clone Embed, location:repo overview"> |
| 228 Embed |
| 229 </button> |
| 230 </div> |
| 231 <input type="text" class="form-control input-monospace input-sm js-zeroclipboard
-target js-url-field" value="<script src="https://gist.github.com/eernst
g/4353d7b4f669745bed3a5423e04a453c.js"></script>" aria-label="Clon
e this repository at <script src="https://gist.github.com/eernstg/4353d7
b4f669745bed3a5423e04a453c.js"></script>" readonly> |
| 232 <div class="input-group-button"> |
| 233 <button aria-label="Copy to clipboard" class="js-zeroclipboard btn btn-sm zero
clipboard-button tooltipped tooltipped-s" data-copied-hint="Copied!" type="butto
n"><svg aria-hidden="true" class="octicon octicon-clippy" height="16" version="1
.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M2 13h4v1H2v-1zm
5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2
c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-
1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.
45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"/
></svg></button> |
| 234 </div> |
| 235 |
| 236 </div> |
| 237 |
| 238 <div class="select-menu-modal-holder"> |
| 239 <div class="select-menu-modal js-menu-content"> |
| 240 <div class="select-menu-header"> |
| 241 <svg aria-label="Close" class="octicon octicon-x js-menu-close" height
="16" role="img" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="e
venodd" d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.
25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"/></svg> |
| 242 <span class="select-menu-title">What would you like to do?</span> |
| 243 </div> |
| 244 |
| 245 <div class="select-menu-list js-navigation-container" role="menu"> |
| 246 <div class="select-menu-item js-navigation-item selected" role="menu
item" tabindex="0"> |
| 247 <svg aria-hidden="true" class="octicon octicon-check select-menu-i
tem-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-ru
le="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"/></svg> |
| 248 <div class="select-menu-item-text"> |
| 249 <input type="radio" name="protocol_selector" value="embed" check
ed> |
| 250 <span class="select-menu-item-heading"> |
| 251 |
| 252 Embed |
| 253 </span> |
| 254 <span class="description"> |
| 255 Embed this gist in your website. |
| 256 </span> |
| 257 <span class="js-select-button-text hidden-select-button-text"> |
| 258 <div class="input-group-button"> |
| 259 <button type="button" class="btn btn-sm select-menu-button js-menu-target" dat
a-ga-click="Repository, clone Embed, location:repo overview"> |
| 260 Embed |
| 261 </button> |
| 262 </div> |
| 263 <input type="text" class="form-control input-monospace input-sm js-zeroclipboard
-target js-url-field" value="<script src="https://gist.github.com/eernst
g/4353d7b4f669745bed3a5423e04a453c.js"></script>" aria-label="Clon
e this repository at <script src="https://gist.github.com/eernstg/4353d7
b4f669745bed3a5423e04a453c.js"></script>" readonly> |
| 264 <div class="input-group-button"> |
| 265 <button aria-label="Copy to clipboard" class="js-zeroclipboard btn btn-sm zero
clipboard-button tooltipped tooltipped-s" data-copied-hint="Copied!" type="butto
n"><svg aria-hidden="true" class="octicon octicon-clippy" height="16" version="1
.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M2 13h4v1H2v-1zm
5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2
c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-
1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.
45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"/
></svg></button> |
| 266 </div> |
| 267 |
| 268 </span> |
| 269 </div> |
| 270 </div> |
| 271 <div class="select-menu-item js-navigation-item " role="menuitem" ta
bindex="0"> |
| 272 <svg aria-hidden="true" class="octicon octicon-check select-menu-i
tem-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-ru
le="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"/></svg> |
| 273 <div class="select-menu-item-text"> |
| 274 <input type="radio" name="protocol_selector" value="share" > |
| 275 <span class="select-menu-item-heading"> |
| 276 |
| 277 Share |
| 278 </span> |
| 279 <span class="description"> |
| 280 Copy sharable URL for this gist. |
| 281 </span> |
| 282 <span class="js-select-button-text hidden-select-button-text"> |
| 283 <div class="input-group-button"> |
| 284 <button type="button" class="btn btn-sm select-menu-button js-menu-target" dat
a-ga-click="Repository, clone Share, location:repo overview"> |
| 285 Share |
| 286 </button> |
| 287 </div> |
| 288 <input type="text" class="form-control input-monospace input-sm js-zeroclipboard
-target js-url-field" value="https://gist.github.com/eernstg/4353d7b4f669745bed3
a5423e04a453c" aria-label="Clone this repository at https://gist.github.com/eern
stg/4353d7b4f669745bed3a5423e04a453c" readonly> |
| 289 <div class="input-group-button"> |
| 290 <button aria-label="Copy to clipboard" class="js-zeroclipboard btn btn-sm zero
clipboard-button tooltipped tooltipped-s" data-copied-hint="Copied!" type="butto
n"><svg aria-hidden="true" class="octicon octicon-clippy" height="16" version="1
.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M2 13h4v1H2v-1zm
5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2
c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-
1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.
45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"/
></svg></button> |
| 291 </div> |
| 292 |
| 293 </span> |
| 294 </div> |
| 295 </div> |
| 296 <div class="select-menu-item js-navigation-item " role="menuitem" ta
bindex="0"> |
| 297 <svg aria-hidden="true" class="octicon octicon-check select-menu-i
tem-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-ru
le="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"/></svg> |
| 298 <div class="select-menu-item-text"> |
| 299 <input type="radio" name="protocol_selector" value="http" > |
| 300 <span class="select-menu-item-heading"> |
| 301 Clone via |
| 302 HTTPS |
| 303 </span> |
| 304 <span class="description"> |
| 305 Clone with Git or checkout with SVN using the repository's w
eb address. |
| 306 </span> |
| 307 <span class="js-select-button-text hidden-select-button-text"> |
| 308 <div class="input-group-button"> |
| 309 <button type="button" class="btn btn-sm select-menu-button js-menu-target" dat
a-ga-click="Repository, clone HTTPS, location:repo overview"> |
| 310 HTTPS |
| 311 </button> |
| 312 </div> |
| 313 <input type="text" class="form-control input-monospace input-sm js-zeroclipboard
-target js-url-field" value="https://gist.github.com/4353d7b4f669745bed3a5423e04
a453c.git" aria-label="Clone this repository at https://gist.github.com/4353d7b4
f669745bed3a5423e04a453c.git" readonly> |
| 314 <div class="input-group-button"> |
| 315 <button aria-label="Copy to clipboard" class="js-zeroclipboard btn btn-sm zero
clipboard-button tooltipped tooltipped-s" data-copied-hint="Copied!" type="butto
n"><svg aria-hidden="true" class="octicon octicon-clippy" height="16" version="1
.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M2 13h4v1H2v-1zm
5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2
c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-
1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.
45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"/
></svg></button> |
| 316 </div> |
| 317 |
| 318 </span> |
| 319 </div> |
| 320 </div> |
| 321 </div> |
| 322 <div class="select-menu-list" role="menu"> |
| 323 <a class="select-menu-item select-menu-action" href="https://help.gith
ub.com/articles/which-remote-url-should-i-use" target="_blank"> |
| 324 <svg aria-hidden="true" class="octicon octicon-question select-menu-
item-icon" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-r
ule="evenodd" d="M6 10h2v2H6v-2zm4-3.5C10 8.64 8 9 8 9H6c0-.55.45-1 1-1h.5c.28 0
.5-.22.5-.5v-1c0-.28-.22-.5-.5-.5h-1c-.28 0-.5.22-.5.5V7H4c0-1.5 1.5-3 3-3s3 1
3 2.5zM7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3
.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7z"/>
</svg> |
| 325 <div class="select-menu-item-text"> |
| 326 Learn more about clone URLs |
| 327 </div> |
| 328 </a> |
| 329 </div> |
| 330 </div> |
| 331 </div> |
| 332 </div> |
| 333 </div> |
| 334 |
| 335 |
| 336 <div class="file-navigation-option"> |
| 337 </div> |
| 338 |
| 339 |
| 340 <div class="file-navigation-option"> |
| 341 <a href="/eernstg/4353d7b4f669745bed3a5423e04a453c/archive/3b9e040372930e7
c263fc075dd6997210586d659.zip" |
| 342 class="btn btn-sm" |
| 343 rel="nofollow" |
| 344 data-ga-click="Gist, download zip, location:gist overview"> |
| 345 Download ZIP |
| 346 </a> |
| 347 </div> |
| 348 </div> |
| 349 |
| 350 <div class="float-left"> |
| 351 <nav class="reponav js-repo-nav js-sidenav-container-pjax" |
| 352 role="navigation" |
| 353 data-pjax="#gist-pjax-container"> |
| 354 |
| 355 <a href="/eernstg/4353d7b4f669745bed3a5423e04a453c" aria-label="Code" class="j
s-selected-navigation-item selected reponav-item" data-hotkey="g c" data-pjax="t
rue" data-selected-links="gist_code /eernstg/4353d7b4f669745bed3a5423e04a453c"> |
| 356 <svg aria-hidden="true" class="octicon octicon-code" height="16" version="1.
1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M9.5 3L8 4.5 11.5
8 8 11.5 9.5 13 14 8 9.5 3zm-5 0L0 8l4.5 5L6 11.5 2.5 8 6 4.5 4.5 3z"/></svg> |
| 357 Code |
| 358 </a> |
| 359 <a href="/eernstg/4353d7b4f669745bed3a5423e04a453c/revisions" aria-label="Re
visions" class="js-selected-navigation-item reponav-item" data-hotkey="g r" data
-pjax="true" data-selected-links="gist_revisions /eernstg/4353d7b4f669745bed3a54
23e04a453c/revisions"> |
| 360 <svg aria-hidden="true" class="octicon octicon-git-commit" height="16" ver
sion="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M10.86 7c
-.45-1.72-2-3-3.86-3-1.86 0-3.41 1.28-3.86 3H0v2h3.14c.45 1.72 2 3 3.86 3 1.86 0
3.41-1.28 3.86-3H14V7h-3.14zM7 10.2c-1.22 0-2.2-.98-2.2-2.2 0-1.22.98-2.2 2.2-2
.2 1.22 0 2.2.98 2.2 2.2 0 1.22-.98 2.2-2.2 2.2z"/></svg> |
| 361 Revisions |
| 362 <span class="Counter">22</span> |
| 363 </a> |
| 364 |
| 365 </nav> |
| 366 |
| 367 </div> |
| 368 </div> |
| 369 |
| 370 |
| 371 </div> |
| 372 </div> |
| 373 |
| 374 <div class="container new-discussion-timeline experiment-repo-nav"> |
| 375 <div class="repository-content gist-content"> |
| 376 |
| 377 <div> |
| 378 <div class="repository-meta js-details-container Details"> |
| 379 <div class="repository-meta-content" itemprop="about"> |
| 380 INFORMAL SPECIFICATION: Generic Method Syntax |
| 381 </div> |
| 382 </div> |
| 383 |
| 384 |
| 385 <div class="js-gist-file-update-container js-task-list-container file-bo
x"> |
| 386 <div id="file-genericmethodsyntax-md" class="file"> |
| 387 <div class="file-header"> |
| 388 <div class="file-actions"> |
| 389 |
| 390 <a href="/eernstg/4353d7b4f669745bed3a5423e04a453c/raw/3b9e040372930e7
c263fc075dd6997210586d659/GenericMethodSyntax.md" class="btn btn-sm ">Raw</a> |
| 391 </div> |
| 392 <div class="file-info"> |
| 393 <span class="icon"> |
| 394 <svg aria-hidden="true" class="octicon octicon-gist" height="16" ver
sion="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M7.5 5L10
7.5 7.5 10l-.75-.75L8.5 7.5 6.75 5.75 7.5 5zm-3 0L2 7.5 4.5 10l.75-.75L3.5 7.5l
1.75-1.75L4.5 5zM0 13V2c0-.55.45-1 1-1h10c.55 0 1 .45 1 1v11c0 .55-.45 1-1 1H1c-
.55 0-1-.45-1-1zm1 0h10V2H1v11z"/></svg> |
| 395 </span> |
| 396 <a class="tooltipped tooltipped-s css-truncate" aria-label="Permalink"
href="#file-genericmethodsyntax-md"> |
| 397 <strong class="user-select-contain gist-blob-name css-truncate-targe
t"> |
| 398 GenericMethodSyntax.md |
| 399 </strong> |
| 400 </a> |
| 401 </div> |
| 402 </div> |
| 403 |
| 404 <div id="readme" class="readme blob instapaper_body"> |
| 405 <article class="markdown-body entry-content" itemprop="text"><h1><a id="user
-content-feature-generic-method-syntax" class="anchor" href="#feature-generic-me
thod-syntax" aria-hidden="true"><svg aria-hidden="true" class="octicon octicon-l
ink" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="e
venodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.4
1-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-
2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5
0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3
-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Feature: Generic Method Syntax</h1> |
| 406 <h2><a id="user-content-feature-generic-method-syntax-1" class="anchor" href="#f
eature-generic-method-syntax-1" aria-hidden="true"><svg aria-hidden="true" class
="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"
><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0
3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8
4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-
.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55
13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Feature: Generic M
ethod Syntax</h2> |
| 407 <p><strong>This document</strong> is an informal specification of the support fo
r generic methods and functions which has been implemented in <code>dart2js</cod
e> with option <code>--generic-method-syntax</code>, starting with commit <a hre
f="https://github.com/dart-lang/sdk/commit/acc5f59a99d5d8747459c935e6360ac325606
cc6">acc5f59</a>. In SDK 1.21 this feature is available by default (i.e., also w
ithout the option) in the virtual machine and the analyzer, as well as in <code>
dart2js</code>.</p> |
| 408 <p>The <strong>motivation for</strong> having this <strong>feature</strong> is t
hat it enables partial support for generic methods and functions, thus providing
a bridge between not having generic methods and having full support for generic
methods. In particular, code declaring and using generic methods may be type ch
ecked and compiled in strong mode, and the same code will now be acceptable in s
tandard (non-strong) mode as well. The semantics is different in certain cases,
but standard mode analysis will emit diagnostic messages (e.g., errors) for that
.</p> |
| 409 <p>In this document, the word <strong>routine</strong> will be used when referri
ng to something which can be a method, a top level function, a local function, o
r a function literal expression.</p> |
| 410 <p>With <strong>this feature</strong> it is possible to compile code where gener
ic methods and functions are declared, implemented, and invoked. The runtime sem
antics does not include reification of type arguments. Evaluations of the runtim
e value of a routine type parameter is a runtime error or yields <code>dynamic</
code>, depending on the context. No type checking takes place at usages of a met
hod or function type parameter in the body, and no type checking regarding expli
citly specified or omitted type arguments takes place at call sites.</p> |
| 411 <p>In short, generic methods and functions are supported syntactically, and the
runtime semantics prevents dynamic usages of the type argument values, but it al
lows all usages where that dynamic value is not required. For instance, a generi
c routine type parameter, <code>T</code>, cannot be used in an expression like <
code>x is T</code>, but it can be used as a type annotation. In a context where
other tools may perform type checking, this allows for a similar level of expres
sive power as do language designs where type arguments are erased at compile tim
e.</p> |
| 412 <p>The <strong>motivation for</strong> this <strong>document</strong> is that it
serves as an informal specification for the implementation of support for the g
eneric method syntax feature in all Dart tools.</p> |
| 413 <h2><a id="user-content-syntax" class="anchor" href="#syntax" aria-hidden="true"
><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1"
viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-
1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45
1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2
1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09
.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></pat
h></svg></a>Syntax</h2> |
| 414 <p>The syntactic elements which are added or modified in order to support this f
eature are as follows, based on grammar rules given in the Dart Language Specifi
cation (Aug 19, 2015).</p> |
| 415 <pre><code>formalParameterPart: |
| 416 typeParameters? formalParameterList |
| 417 functionSignature: |
| 418 metadata returnType? identifier formalParameterPart |
| 419 typeParameter: |
| 420 metadata identifier (('extends'|'super') type)? |
| 421 functionExpression: |
| 422 formalParameterPart functionBody |
| 423 fieldFormalParameter: |
| 424 metadata finalConstVarOrType? 'this' '.' identifier |
| 425 formalParameterPart? |
| 426 argumentPart: |
| 427 typeArguments? arguments |
| 428 selector: |
| 429 assignableSelector | argumentPart |
| 430 assignableExpression: |
| 431 primary (argumentPart* assignableSelector)+ | |
| 432 'super' unconditionalAssignableSelector | |
| 433 identifier |
| 434 cascadeSection: |
| 435 '..' (cascadeSelector argumentPart*) |
| 436 (assignableSelector argumentPart*)* |
| 437 (assignmentOperator expressionWithoutCascade)? |
| 438 </code></pre> |
| 439 <p>In a <a href="https://codereview.chromium.org/1177073002">draft specification
</a> of generic methods from June 2015, the number of grammar changes is signifi
cantly higher, but that form can be obtained via renaming.</p> |
| 440 <p>This extension to the grammar gives rise to an <strong>ambiguity</strong> whe
re the same tokens may be angle brackets of a type argument list as well as rela
tional operators. For instance, <code>foo(a<b,c>(d))</code>[^1] may be par
sed as a <code>postfixExpression</code> on the form <code>primary arguments</cod
e> where the arguments are two relational expressions (<code>a<b</code> and <
code>c>(d)</code>), and it may also be parsed such that there is a single ar
gument which is an invocation of a generic function (<code>a<b,c>(d)</code
>). The ambiguity is resolved in <strong>favor</strong> of the <strong>generic
function invocation</strong> whenever the <code>primary</code> is followed by a
balanced pair of angle brackets where the next token after the final <code>><
/code> is a left parenthesis (in short, we are "looking at <code>< .. >(</
code>").</p> |
| 441 <p>This implies that an expression like <code>foo(a<b,2>(d))</code> will b
e rejected because it is parsed such that <code>foo</code> gets one argument whi
ch must be a generic function invocation, but <code>2</code> cannot parse correc
tly as a <code>type</code>. This is a breaking change, because the same expressi
on used to parse correctly as an invocation of <code>foo</code> with two argumen
ts.</p> |
| 442 <p>The <strong>reason</strong> why the generic function invocation is favored ov
er the relational expressions is that it is considered to be a rare exception th
at this ambiguity arises: It requires a balanced set of angle brackets followed
by a left parenthesis, which is already an unusual form. On top of that, the sty
le guide recommendation to use named parameters for boolean arguments helps maki
ng this situation even less common.</p> |
| 443 <p>If it does occur then there is an easy <strong>workaround</strong>: an extra
set of parentheses (as in <code>foo(a<b,(2>(d)))</code>) will resolve the
ambiguity in the direction of relational expressions; or we might simply be able
to remove the parentheses around the last expression (as in <code>foo(a<b,2&
gt;d)</code>), which will also eliminate the ambiguity.</p> |
| 444 <p>It should be noted that parsing techniques like recursive descent seem to con
flict with this approach to disambiguation: Determining whether the remaining in
put starts with a balanced expression on the form <code><</code> .. <code>>
;</code> seems to imply a need for an unbounded lookahead. However, if some type
of "diet" parsing is used and various kinds of bracket tokens are matched up du
ring the lexical analysis then it takes only a simple O(1) check in the parser t
o perform the required check.</p> |
| 445 <h2><a id="user-content-scope-of-the-mechanism" class="anchor" href="#scope-of-t
he-mechanism" aria-hidden="true"><svg aria-hidden="true" class="octicon octicon-
link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="
evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.
41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22
-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5
0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0
3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Scope of the Mechanism</h2> |
| 446 <p>With the syntax in place, it is obvious that certain potential extensions hav
e <strong>not</strong> been <strong>included</strong>.</p> |
| 447 <p>For instance, constructors, setters, getters, and operators cannot be declare
d as generic. Actual type arguments cannot be passed at invocation sites for set
ters, getters, and operators, and for constructors there is a need to find a way
to distinguish between type arguments for the new instance and type arguments f
or the constructor itself. It is possible that some of these restrictions will b
e lifted in a full-fledged version of this extension.</p> |
| 448 <p>Conversely, the inclusion of lower bounds for type parameters (using the keyw
ord <code>super</code>) serves to demonstrate that lower bounds fit well into th
e syntax. There is no guarantee that a final version of generic methods will sup
port lower bounds, and it is not required that an implementation must support th
em.</p> |
| 449 <p>In general, the support for generic methods offered by this feature is not in
tended to be complete, it is <strong>intended</strong> to allow <strong>for</str
ong> <strong>experiments</strong> such that a final version of the generic metho
d support can be designed well, <strong>and</strong> it is intended to allow for
the <strong>subset of usages</strong> where reification is not required.</p> |
| 450 <h2><a id="user-content-resolution-and-type-checking" class="anchor" href="#reso
lution-and-type-checking" aria-hidden="true"><svg aria-hidden="true" class="octi
con octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path
fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.6
9 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-
.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-
2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9
13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Resolution and Type Chec
king</h2> |
| 451 <p>In order to be useful, the support for generic methods and functions must be
sufficiently complete and consistent to <strong>avoid spurious</strong> diagnost
ic <strong>messages</strong>. In particular, even though no regular type checks
take place at usages of routine type parameters in the body where they are in sc
ope, those type parameters should be resolved. If they had been ignored then any
usage of a routine type parameter <code>X</code> would give rise to a <code>Can
not resolve type X</code> error message, or the usage might resolve to other dec
larations of <code>X</code> in enclosing scopes such as a class type parameter,
both of which is unacceptable.</p> |
| 452 <p>In <code>dart2js</code> resolution, the desired behavior has been achieved by
adding a new type parameter <strong>scope</strong> and putting the type paramet
ers into that scope, giving each of them the bound <code>dynamic</code>. The typ
e parameter scope is the current scope during resolution of the routine signatur
e and the type parameter bounds, it encloses the formal parameter scope of the r
outine, and the formal parameter scope in turn encloses the body scope.</p> |
| 453 <p>This implies that every usage of a routine type parameter is treated during <
strong>type checking</strong> as if it had been an alias for the type <code>dyna
mic</code>.</p> |
| 454 <p>Static checks for <strong>invocations</strong> of methods or functions where
type arguments are passed are omitted entirely: The type arguments are parsed, b
ut no checks are applied to certify that the given routine accepts type argument
s, and no checks are applied for bound violations. Similarly, no checks are perf
ormed for invocations where no type arguments are passed, whether or not the giv
en routine is statically known to accept type arguments.</p> |
| 455 <p>Certain usages of a routine type parameter <code>X</code> give rise to <stron
g>errors</strong>: It is a compile-time error if <code>X</code> is used as a typ
e literal (e.g., <code>foo(X)</code>), or in an expression on the form <code>e i
s X</code> or <code>e is! X</code>.</p> |
| 456 <p>It could be argued that it should be a warning or an error if a routine type
parameter <code>X</code> is used in an expression on the form <code>e as X</code
>. The blind success of this test at runtime may introduce bugs into correct pro
grams in situations where the type constraint is violated; in particular, this c
ould cause "wrong" objects to propagate through local variables and parameters a
nd even into data structures (say, when a <code>List<T></code> is actually
a <code>List<dynamic></code>, because <code>T</code> is not present at ru
ntime when the list is created). However, considering that these type constraint
violations are expected to be rare, and considering that it is common to requir
e that programs compile without warnings, we have chosen to omit this warning. A
tool is still free to emit a hint, or in some other way indicate that there is
an issue.</p> |
| 457 <h2><a id="user-content-dynamic-semantics" class="anchor" href="#dynamic-semanti
cs" aria-hidden="true"><svg aria-hidden="true" class="octicon octicon-link" heig
ht="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d
="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.7
2-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9
4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-
1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3
.5S14.5 6 13 6z"></path></svg></a>Dynamic semantics</h2> |
| 458 <p>If a routine invocation specifies actual type arguments, e.g., <code>int</cod
e> in the <strong>invocation</strong> <code>f<int>(42)</code>, those type
arguments will not be evaluated at runtime, and they will not be passed to the r
outine in the invocation. Similarly, no type arguments are ever passed to a gene
ric routine due to call-site inference. This corresponds to the fact that the ty
pe arguments have no runtime representation.</p> |
| 459 <p>When the body of a generic <strong>routine</strong> is <strong>executed</stro
ng>, usages of the formal type parameters will either result in a run-time error
, or they will yield the value yielded by an evaluation of <code>dynamic</code>,
following the treatment of malformed types in Dart. There are the following cas
es:</p> |
| 460 <p>When <code>X</code> is a routine type parameter, the evaluation of <code>e is
X</code>, <code>e is! X</code>, and <code>X</code> used as a type literal proce
eds as if <code>X</code> had been a malformed type, producing a dynamic error if
the type test itself is reached; the evaluation of <code>e as X</code> has the
same outcome as the evaluation of <code>e</code>.</p> |
| 461 <p>Note that the forms containing <code>is</code> are compile-time errors, which
means that implementations are free to reject the program, or to compile the pr
ogram with a different runtime semantics for these expressions. The rationale fo
r <code>dart2js</code> to allow the construct and compile it to a run time error
is that (1) this allows more programs using generic methods to be compiled, and
(2) an <code>is</code> expression that blindly returns <code>true</code> every
time (or <code>false</code> every time) may silently introduce a bug into an oth
erwise correct program, so the expression must fail if it is ever evaluated.</p> |
| 462 <p>When <code>X</code> is a routine type parameter which is passed as a type arg
ument to a generic class instantiation <code>G</code> which is itself used in <c
ode>e is G</code>, <code>e is! G</code>, <code>e as G</code>, and <code>G</code>
used as a type literal, evaluation again proceeds as if <code>X</code> were a m
alformed type, which in this case means that it is treated like <code>dynamic</c
ode>.</p> |
| 463 <p>This may be surprising, so let us consider a couple of examples: When <code>X
</code> is a routine type parameter, <code>42 is X</code> raises a dynamic error
, <code><int>[42] is List<X></code> yields the value <code>true</cod
e>, and <code>42 as X</code> yields <code>42</code>, no matter whether the synta
x for the invocation of the routine included an actual type argument, and, if so
, no matter which value the actual type argument would have had at the invocatio
n.</p> |
| 464 <p>Object construction is similar: When <code>X</code> is a routine type paramet
er which is a passed as a type argument to a constructor invocation, the value p
assed to the constructor will be the value yielded by an evaluation of <code>dyn
amic</code>.</p> |
| 465 <p>In <strong>checked mode</strong>, when <code>X</code> is a routine type param
eter which is used as a type annotation or in a generic type <code>G</code> used
as a type annotation, no checked mode checks will ever fail for initialization
or assignment to a local variable or parameter whose type annotation is <code>X<
/code>, and if the type annotation is a generic type <code>G</code> that contain
s <code>X</code>, checked mode checks will succeed or fail as if <code>X</code>
had been the type <code>dynamic</code>.</p> |
| 466 <h2><a id="user-content-changes" class="anchor" href="#changes" aria-hidden="tru
e"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1
" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-
3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.4
5 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0
2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.
09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></p
ath></svg></a>Changes</h2> |
| 467 <p>2017-Jan-04: Changed 'static error' to 'compile-time error', which is the phr
ase that the language specification uses.</p> |
| 468 <h2><a id="user-content-notes" class="anchor" href="#notes" aria-hidden="true"><
svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" vi
ewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.
69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-
1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1
.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.5
3-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path>
</svg></a>Notes</h2> |
| 469 <p>[^1]: These expressions violate the common style in Dart with respect to spac
ing and capitalization. That is because the ambiguity implies conflicting requir
ements, and we do not want to bias the appearance in one of the two directions.<
/p> |
| 470 </article> |
| 471 </div> |
| 472 |
| 473 </div> |
| 474 |
| 475 </div> |
| 476 |
| 477 |
| 478 <a name="comments"></a> |
| 479 <div class="discussion-timeline gist-discussion-timeline js-quote-selection-
container "> |
| 480 <div class="js-discussion js-socket-channel" data-channel="marked-as-read:
gist:41132114"> |
| 481 |
| 482 |
| 483 |
| 484 |
| 485 |
| 486 <!-- Rendered timeline since 2017-01-26 08:00:50 --> |
| 487 <div id="partial-timeline-marker" |
| 488 class="js-timeline-marker js-updatable-content" |
| 489 data-url="/eernstg/4353d7b4f669745bed3a5423e04a453c/show_partial?partial=g
ist%2Ftimeline_marker&since=1485446450" |
| 490 data-last-modified="Thu, 26 Jan 2017 16:00:50 GMT" |
| 491 > |
| 492 </div> |
| 493 |
| 494 |
| 495 <div class="discussion-timeline-actions"> |
| 496 <div class="flash flash-warn mt-3"> |
| 497 <a href="/join?source=comment-gist" class="btn btn-primary" rel="nofollow">S
ign up for free</a> |
| 498 <strong>to join this conversation on GitHub</strong>. |
| 499 Already have an account? |
| 500 <a href="/login?return_to=https%3A%2F%2Fgist.github.com%2Feernstg%2F4353d7b4
f669745bed3a5423e04a453c" rel="nofollow">Sign in to comment</a> |
| 501 </div> |
| 502 |
| 503 </div> |
| 504 </div> |
| 505 </div> |
| 506 </div> |
| 507 </div> |
| 508 |
| 509 <div class="modal-backdrop js-touch-events"></div> |
| 510 </div><!-- /.container --> |
| 511 |
| 512 </div> |
| 513 </div> |
| 514 |
| 515 </div> |
| 516 |
| 517 <div class="container site-footer-container"> |
| 518 <div class="site-footer" role="contentinfo"> |
| 519 <ul class="site-footer-links float-right"> |
| 520 <li><a href="https://github.com/contact" data-ga-click="Footer, go to co
ntact, text:contact">Contact GitHub</a></li> |
| 521 <li><a href="https://developer.github.com" data-ga-click="Footer, go to ap
i, text:api">API</a></li> |
| 522 <li><a href="https://training.github.com" data-ga-click="Footer, go to tra
ining, text:training">Training</a></li> |
| 523 <li><a href="https://shop.github.com" data-ga-click="Footer, go to shop, t
ext:shop">Shop</a></li> |
| 524 <li><a href="https://github.com/blog" data-ga-click="Footer, go to blog,
text:blog">Blog</a></li> |
| 525 <li><a href="https://github.com/about" data-ga-click="Footer, go to abou
t, text:about">About</a></li> |
| 526 |
| 527 </ul> |
| 528 |
| 529 <a href="https://github.com" aria-label="Homepage" class="site-footer-mark"
title="GitHub"> |
| 530 <svg aria-hidden="true" class="octicon octicon-mark-github" height="24" ve
rsion="1.1" viewBox="0 0 16 16" width="24"><path fill-rule="evenodd" d="M8 0C3.5
8 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1
.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.6
3-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64
-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.
64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.9
2.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0
1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-
8z"/></svg> |
| 531 </a> |
| 532 <ul class="site-footer-links"> |
| 533 <li>© 2017 <span title="0.13594s from github-fe124-cp1-prd.iad.github
.net">GitHub</span>, Inc.</li> |
| 534 <li><a href="https://github.com/site/terms" data-ga-click="Footer, go to
terms, text:terms">Terms</a></li> |
| 535 <li><a href="https://github.com/site/privacy" data-ga-click="Footer, go
to privacy, text:privacy">Privacy</a></li> |
| 536 <li><a href="https://github.com/security" data-ga-click="Footer, go to s
ecurity, text:security">Security</a></li> |
| 537 <li><a href="https://status.github.com/" data-ga-click="Footer, go to st
atus, text:status">Status</a></li> |
| 538 <li><a href="https://help.github.com" data-ga-click="Footer, go to help,
text:help">Help</a></li> |
| 539 </ul> |
| 540 </div> |
| 541 </div> |
| 542 |
| 543 |
| 544 |
| 545 |
| 546 |
| 547 <div id="ajax-error-message" class="ajax-error-message flash flash-error"> |
| 548 <svg aria-hidden="true" class="octicon octicon-alert" height="16" version="1
.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.865 1.52c-.18
-.31-.51-.5-.87-.5s-.69.19-.87.5L.275 13.5c-.18.31-.18.69 0 1 .19.31.52.5.87.5h1
3.7c.36 0 .69-.19.86-.5.17-.31.18-.69.01-1L8.865 1.52zM8.995 13h-2v-2h2v2zm0-3h-
2V6h2v4z"/></svg> |
| 549 <button type="button" class="flash-close js-flash-close js-ajax-error-dismis
s" aria-label="Dismiss error"> |
| 550 <svg aria-hidden="true" class="octicon octicon-x" height="16" version="1.1
" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M7.48 8l3.75 3.75-
1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75
1.48 1.48z"/></svg> |
| 551 </button> |
| 552 You can't perform that action at this time. |
| 553 </div> |
| 554 |
| 555 |
| 556 <script crossorigin="anonymous" src="https://assets-cdn.github.com/assets/co
mpat-8a4318ffea09a0cdb8214b76cf2926b9f6a0ced318a317bed419db19214c690d.js"></scri
pt> |
| 557 <script crossorigin="anonymous" src="https://assets-cdn.github.com/assets/fr
ameworks-6d109e75ad8471ba415082726c00c35fb929ceab975082492835f11eca8c07d9.js"></
script> |
| 558 <script async="async" crossorigin="anonymous" src="https://assets-cdn.github
.com/assets/github-55316b70ec9eb5a4dd5cd168f8f8da4d5fe20c53564512dd5aace9898aed7
0c5.js"></script> |
| 559 |
| 560 |
| 561 |
| 562 |
| 563 <div class="js-stale-session-flash stale-session-flash flash flash-warn flash-
banner d-none"> |
| 564 <svg aria-hidden="true" class="octicon octicon-alert" height="16" version="1
.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.865 1.52c-.18
-.31-.51-.5-.87-.5s-.69.19-.87.5L.275 13.5c-.18.31-.18.69 0 1 .19.31.52.5.87.5h1
3.7c.36 0 .69-.19.86-.5.17-.31.18-.69.01-1L8.865 1.52zM8.995 13h-2v-2h2v2zm0-3h-
2V6h2v4z"/></svg> |
| 565 <span class="signed-in-tab-flash">You signed in with another tab or window.
<a href="">Reload</a> to refresh your session.</span> |
| 566 <span class="signed-out-tab-flash">You signed out in another tab or window.
<a href="">Reload</a> to refresh your session.</span> |
| 567 </div> |
| 568 <div class="facebox" id="facebox" style="display:none;"> |
| 569 <div class="facebox-popup"> |
| 570 <div class="facebox-content" role="dialog" aria-labelledby="facebox-header"
aria-describedby="facebox-description"> |
| 571 </div> |
| 572 <button type="button" class="facebox-close js-facebox-close" aria-label="Clo
se modal"> |
| 573 <svg aria-hidden="true" class="octicon octicon-x" height="16" version="1.1
" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M7.48 8l3.75 3.75-
1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75
1.48 1.48z"/></svg> |
| 574 </button> |
| 575 </div> |
| 576 </div> |
| 577 |
| 578 |
| 579 </body> |
| 580 </html> |
| 581 |
OLD | NEW |