blob: 1108595da1a1d5285530b8e8a8fe5e7df448ef80 [file] [log] [blame]
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "../xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../css/ot.css" />
<link rel="stylesheet" type="text/css" href="../css/otjld.css" />
<title>OT/J Language Definition v1.3</title>
</head>
<body class="otdt">
<div id="content">
<table class="nav">
<tr>
<td class="back"><a id="top"></a><a href="s2.2.a.html" rel="prev">&lt;&lt;&nbsp;&sect;2.2.(a)&nbsp;Definition of lowering</a></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"><a href="s2.2.c.html" rel="next">&sect;2.2.(c)&nbsp;Typing&nbsp;&gt;&gt;</a></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s2.html" rel="section">&sect;2&nbsp;Role Binding</a>&nbsp;&gt;&nbsp;<a class="nav" href="s2.2.html" rel="section">&sect;2.2&nbsp;Lowering</a></div>
<div class="subsect depth3" id="s2.2.b">
<h4 class="subsect">&sect;2.2.(b)&nbsp;<span class="title">Places of lowering</span><a class="img" href="s2.2.b.html"
title="PermaLink to (b)&nbsp;Places of lowering"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>The lowering translation is not meant to be invoked
by client code, but <strong>implicit translations</strong> are inserted by
the compiler at all places where a role type is provided while the
corresponding base type (or a super type) was expected.<br />
In other words: lowering translations are inserted by the compiler at
all places in a program which would otherwise not be type correct
and which using lowering are statically type correct.
This may concern:
</p>
<ul>
<li>the right hand side of an assignment wrt. the static type of the left hand side,</li>
<li>the argument values of a method or constructor call wrt. the static type of the corresponding formal parameter,</li>
<li>the return value of a method compared to the declared return type of the method.</li>
<li>a role parameter in a callout binding (<a href="s3.3.d.html" title="&sect;3.3.(d)&nbsp;Typing rules" class="sect">&sect;3.3.(d)</a>)
</li>
<li>or the return value in a callin binding (<a href="s4.5.d.html" title="&sect;4.5.(d)&nbsp;Typing rules" class="sect">&sect;4.5.(d)</a>)
</li>
</ul>
<div class="listing example frame">
<table class="listing">
<tr class="line odd">
<td class="ln">1</td>
<td><pre><b>public</b> <b>team</b> <b>class</b> MyTeamA {</pre></td>
</tr>
<tr class="line even">
<td class="ln">2</td>
<td><pre> <b>public</b> <b>class</b> <em>MyRole <b>playedBy</b> MyBase</em> { ... }</pre></td>
</tr>
<tr class="line odd">
<td class="ln">3</td>
<td><pre> <b>void</b> useMyBase(<em>MyBase</em> myb) {...}</pre></td>
</tr>
<tr class="line even">
<td class="ln">4</td>
<td><pre> <em>MyRole</em> returnMyRole() {...}</pre></td>
</tr>
<tr class="line odd">
<td class="ln">5</td>
<td><pre> <b>public</b> <b>void</b> doSomething() {</pre></td>
</tr>
<tr class="line even">
<td class="ln">6</td>
<td><pre> <em>MyRole r</em> = <b>new</b> MyRole(<b>new</b> MyBase());</pre></td>
</tr>
<tr class="line odd">
<td class="ln">7</td>
<td><pre> <em>MyBase b</em> = <em>r</em>;</pre></td>
</tr>
<tr class="line even">
<td class="ln">8</td>
<td><pre> useMyBase(<em>r</em>);</pre></td>
</tr>
<tr class="line odd">
<td class="ln">9</td>
<td><pre> <em>MyBase b2</em> = returnMyRole();</pre></td>
</tr>
<tr class="line even">
<td class="ln">10</td>
<td><pre> }</pre></td>
</tr>
<tr class="line odd">
<td class="ln">11</td>
<td><pre>}</pre></td>
</tr>
</table>
</div>
<div class="codecomment">
<h5>Effects:</h5>
<p>An instance of type <code>MyRole</code> is lowered to type <code>MyBase</code> when
</p>
<ul>
<li>assigning it to <code>b</code> (line 7)
</li>
<li>passing it as argument to a method with formal parameter of type <code>MyBase</code> (line 8)
</li>
<li>assigning the return value to a variable of type <code>MyBase</code> (line 9)
</li>
</ul>
<p><em>Note</em>: The constructor call in line 6 uses the <em>lifting constructor</em> as defined in <a href="s2.4.1.html"
title="&sect;2.4.1&nbsp;Role creation via a lifting constructor"
class="sect">&sect;2.4.1</a></p>
</div>
<p>Lowering translations are <span class="underline">not</span> inserted for
</p>
<ul>
<li>reference comparison (using <code>==</code> or <code>!=</code>)
</li>
<li><code>instanceof</code> checks
</li>
<li>cast expressions</li>
<li>return values in callout bindings <a href="s3.3.d.html" title="&sect;3.3.(d)&nbsp;Typing rules" class="sect">&sect;3.3.(d)</a>)
</li>
<li>parameters in callin bindings (<a href="s4.5.d.html" title="&sect;4.5.(d)&nbsp;Typing rules" class="sect">&sect;4.5.(d)</a>)
</li>
</ul>
<p>For cases where lowering shall be <em>forced</em> see <a href="s2.2.d.html" title="&sect;2.2.(d)&nbsp;Explicit lowering"
class="sect">&sect;2.2.(d)</a> below.
</p>
</div>
<table class="nav">
<tr>
<td class="back"><a href="s2.2.a.html" rel="prev">&lt;&lt;&nbsp;&sect;2.2.(a)&nbsp;Definition of lowering</a></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"><a href="s2.2.c.html" rel="next">&sect;2.2.(c)&nbsp;Typing&nbsp;&gt;&gt;</a></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s2.html" rel="section">&sect;2&nbsp;Role Binding</a>&nbsp;&gt;&nbsp;<a class="nav" href="s2.2.html" rel="section">&sect;2.2&nbsp;Lowering</a></div>
</div>
<div id="footer">
<hr /><a class="w3c img" href="http://jigsaw.w3.org/css-validator/check/referer"
shape="rect"><img src="../images/valid-css2-blue.png" alt="Valid CSS!" height="31" width="88" /></a><a class="w3c img" href="http://validator.w3.org/check?uri=referer" shape="rect"><img src="../images/valid-xhtml10-blue.png" alt="Valid XHTML 1.0 Strict" height="31"
width="88" /></a><address>&copy; Stephan Herrmann, Christine Hundt, Marco Mosconi</address>
OT/J version 1.3 &mdash; last modified: 2011-05-15
</div>
</body>
</html>