wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
fn bar() -> i32 {{ 54 }}
fn bar() -> i32 {{ 54 }}
Correct.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
disp('output')
disp('output')
Correct.
MATLAB
[15, 46, 48
[15, 46, 48]
Close bracket.
Python
if (b = 15) {}
if (b == 15) {}
Use ==.
Dart
<entry><name>info</name><name>94</name></entry
<entry><name>info</name><name>94</name></entry>
Add closing >.
XML
let list=vec![27,13,86]; let first=&list[0]; list.push(90);
let mut list=vec![27,13,86]; let first=list[0]; list.push(90);
Copy instead of reference.
Rust
for (int i=0; i<90; i++) {{}}
for (int i=0; i<90; i++) {{}}
Correct.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
arr[61]
if (arr.indices.contains(61)) arr[61]
Check index.
Kotlin
<note name='test'/>
<note name="test"/>
Double quotes.
XML
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
function test() {{ return {{key:'test'}} }}
function test() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(25);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(25, () => console.log('listening'));
Add callback.
Node.js
if x > 8 puts 'hello'
if x > 8 puts 'hello' end
Add 'end'.
Ruby
let b: i32 = "info";
let b: &str = "info";
Type mismatch.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
function bar(): void {{ return 31; }}
function bar(): number {{ return 31; }}
Return type mismatch.
TypeScript
if b = 29
if b == 29
Use ==.
Ruby
let data = 87; let data = 11;
let data = 87; data = 11;
Duplicate declaration.
JavaScript
else print('hello')
else: print('hello')
Colon after else.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
print 'hello'
print('hello')
Parentheses for function call.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
class Product def method end end
class Product def method end end
Correct.
Ruby
int[] list = new int[20]; list[20] = 5;
int[] list = new int[20]; if (20 < list.length) list[20] = 5;
Check bounds.
Java
String name = 'world';
String name = 'world';
Correct.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let vec=vec![29,85,90]; let primary=&vec[0]; vec.push(12);
let mut vec=vec![29,85,90]; let primary=vec[0]; vec.push(12);
Copy instead of reference.
Rust
SELECT * FROM products WHRE id=31;
SELECT * FROM products WHERE id=31;
Fix WHERE.
SQL
x := 32
x := 32
Correct.
Go
arr[17]
if arr.indices.contains(17) {{ arr[17] }}
Check index.
Swift
let msg = String::from("test"); let r=&msg; msg.push_str("!");
let mut msg = String::from("test"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
function compute(y) print(y) end
function compute(y) print(y) end
Correct.
Lua
let num: i32 = "hello";
let num: &str = "hello";
Type mismatch.
Rust
if temp = 8 then print('data') end
if temp == 8 then print('data') end
Use ==.
Lua
val y = 'data'
val y = "data"
Double quotes.
Kotlin
if ($c = 51) {{}}
if ($c -eq 51) {{}}
Use -eq.
PowerShell
yield val
yield val
Correct yield.
Python
if (a = 31)
if (a == 31)
Use ==.
C++
WHERE age = '21'
WHERE age = 21
Don't quote integer.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
b > 4 & x < 81
b > 4 and x < 81
Use 'and' not '&'.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
object Order {{ def main(args: Array[String]) = println("world") }}
object Order {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
int list[25]; list[25]=5;
int list[25]; if(25<25){{}} else list[25]=5;
Bounds check.
C++
<note name='output'/>
<note name="output"/>
Double quotes.
XML
re.sqrt(73)
import re re.sqrt(73)
Import module first.
Python
disp('info')
disp('info')
Correct.
MATLAB
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(47);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(47);
Correct.
Node.js
if count = 31
if count == 31
Use ==.
Go
UPDATE users SET email='data' WHERE role=11
UPDATE users SET email='data' WHERE role=11;
Add semicolon.
SQL
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
let num: Int = 'info'
let num: String = 'info'
Fix type.
Swift
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
<entry><name>info</name><name>73</name></entry
<entry><name>info</name><name>73</name></entry>
Add closing >.
XML
if (num = 100)
if (num == 100)
Use ==.
R
print('world')
print('world')
Correct.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
local val = 53
local val = 53
Correct.
Lua
if (num = 17) {{}}
if (num === 17) {{}}
Use === for equality.
JavaScript
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
for i=1,85 do print(i) end
for i=1,85 do print(i) end
Correct.
Lua
for (int i=0; i<59; i++) {{}}
for (int i=0; i<59; i++) {{}}
Correct.
Java
my @arr = (29,31,34);
my @arr = (29,31,34);
Correct.
Perl
function baz() {{ echo 'data'; }}
function baz() {{ echo 'data'; }}
Correct.
PHP
if ($z = 30)
if ($z == 30)
Use ==.
Perl
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:62}};
Add missing property.
TypeScript
<br></br>
<br>
Self-closing.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
if (y = 16) {{}}
if (y == 16) {{}}
Use ==.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
while data > 36 data -= 1
while data > 36: data -= 1
Colon missing after while.
Python
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
var item int = 'message'
var item string = 'message'
Type mismatch.
Go
class Order {{ int index; }};
class Order {{ public: int index; }};
Make public.
C++
if (a = 61) {}
if (a == 61) {}
Use ==.
Dart
class Order def method end end
class Order def method end end
Correct.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
def baz(val): return val + 1
def baz(val): return val + 1
Correct.
Python
$val = 14; if ($val = 14) {{}}
$val = 14; if ($val == 14) {{}}
Use ==.
PHP